Silverlight: how to package theme

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.