In Silverlight enterprise development, there will be a large number of style resource files in the project. How can we package these XAML files into DLL to meet the needs of dynamically changing theme? Refer to theme. dll in the Toolkit source code
This article describes the process in detail:
1. Create a Silverlight class library named blackcolortheme.
2. Create the required resourcedictionary
Buttonstyle. XAML and hyperlinkbutton. xaml2 files are created here, and build action is set to resource
Taking buttonstyle as an example, we set a simple style:
<Resourcedictionary
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x= "Http://schemas.microsoft.com/winfx/2006/xaml">
<Style Targettype= "Button" X: Key= "Defaultbuttonstyle">
<Setter Property= "Background" Value= "Black"> </Setter>
</Style>
<Style Targettype= "Button" Basedon= "{Staticresource defaultbuttonstyle }"/>
</Resourcedictionary>
3. Create theme. XAML to introduce our Style File
The build action still needs to be set to resource. The content of theme. XAML is as follows:
<Resourcedictionary
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x= "Http://schemas.microsoft.com/winfx/2006/xaml">
<Resourcedictionary. mergeddictionaries>
<Resourcedictionary Source= "/Blackcolortheme; component/buttonstyle. XAML"> </Resourcedictionary>
<Resourcedictionary Source= "/Blackcolortheme; component/hyperlinkbutton. XAML"> </Resourcedictionary>
</Resourcedictionary. mergeddictionaries>
</Resourcedictionary>
4. Create a blackcolortheme. CS file that inherits the system. Windows. Controls. theming. toolkit. Theme class.
Public ClassBlackcolortheme: Theme
{
Public StaticUri themeresourceuri =NewUri ("/Blackcolortheme; component/theme. XAML", Urikind. relativeorabsolute );
PublicBlackcolortheme ()
:Base(Themeresourceuri)
{
}
Public Static BoolGetisapplicationtheme (Application APP)
{
ReturnGetapplicationthemeuri (APP) = themeresourceuri;
}
Public Static VoidSetisapplicationtheme (Application app,Bool Value)
{
Setapplicationthemeuri (app, themeresourceuri );
}
}
in this step, we have created a loose XAML file and packaged it into a DLL. If you are not familiar with this operation, please refer to my Article : Silverlight topic settings.