Silverlight Tookit provides about 10 theme types, which can be easily implemented in projects based on your preferences.
Dynamic skin effect. Of course, it also officially recommends several theme-making plug-ins. Using these Blend plug-ins can easily generate various
The theme of the style color.
Now, let's start the text of today.
First, download the Tookit file and add the corresponding DLL file: Microsoft. Windows. Controls. Theming. dll.
In the current example, the theme file is also involved. I have placed 10 themes files in this DEMO.
Folder:
And use the "content" method as the "generate operation" option, as follows:
We can directly declare the theme elements in the XAML file, for example:
<UserControl ..
Xmlns: theming = "clr-namespace: Microsoft. Windows. Controls. Theming; assembly = Microsoft. Windows. Controls. Theming"
>
<! -- ShinyDarkPurple -->
& Lt; StackPanel Width = "100"
Theming: ImplicitStyleManager. ApplyMode = "Auto"
Theming: ImplicitStyleManager. ResourceDictionaryUri = "themes/ExpressionLight. xaml">
<Button Content = "Button"/>
<CheckBox Content = "CheckBox"/>
<RadioButton Content = "RadioButton"/>
<Slider/>
<ListBox/>
<ProgressBar Height = "15" Value = "30"/>
<Controls: Expander ExpandDirection = "Down"/>
</StackPanel>
<! -- ShinyDarkGreen -->
</UserControl>
In this way, the ExpressionLight topic is applied to all control styles in the StackPanel. In addition, we can also
Set the corresponding topic for the specified control in the file, such as the code written in this DEMO:
Public Page ()
{
InitializeComponent ();
This. ThemeList. SelectionChanged + = new SelectionChangedEventHandler (ThemeList_SelectionChanged );
This. Loaded + = new RoutedEventHandler (Page_Loaded );
}
Void Page_Loaded (object sender, RoutedEventArgs e)
{
ThemeList. Items. Add (new ComboBoxItem () {Name = "ExpressionDark", Content = "ExpressionDark", DataContext = "themes/ExpressionDark. xaml", IsEnabled = true });
ThemeList. Items. Add (new ComboBoxItem () {Name = "ExpressionLight", Content = "ExpressionLight", DataContext = "themes/ExpressionLight. xaml "});
ThemeList. Items. Add (new ComboBoxItem () {Name = "RainierOrange", Content = "RainierOrange", DataContext = "themes/RainierOrange. xaml "});
ThemeList. Items. Add (new ComboBoxItem () {Name = "RainierPurple", Content = "RainierPurple", DataContext = "themes/RainierPurple. xaml "});
ThemeList. Items. Add (new ComboBoxItem () {Name = "RainierRadialBlue", Content = "RainierRadialBlue", DataContext = "themes/RainierRadialBlue. xaml "});
ThemeList. Items. Add (new ComboBoxItem () {Name = "ShinyBlue", Content = "ShinyBlue", DataContext = "themes/ShinyBlue. xaml "});
ThemeList. Items. Add (new ComboBoxItem () {Name = "ShinyDarkGreen", Content = "ShinyDarkGreen", DataContext = "themes/ShinyDarkGreen. xaml "});
ThemeList. Items. Add (new ComboBoxItem () {Name = "ShinyDarkPurple", Content = "ShinyDarkPurple", DataContext = "themes/ShinyDarkPurple. xaml "});
ThemeList. Items. Add (new ComboBoxItem () {Name = "ShinyDarkTeal", Content = "ShinyDarkTeal", DataContext = "themes/ShinyDarkTeal. xaml "});
ThemeList. Items. Add (new ComboBoxItem () {Name = "ShinyRed", Content = "ShinyRed", DataContext = "themes/ShinyRed. xaml "});
SetTheme (ThemeList. Items [0] as ComboBoxItem );
}
Private void ThemeList_SelectionChanged (object sender, SelectionChangedEventArgs e)
{
SetTheme (ThemeList. SelectedItem as ComboBoxItem );
}
// Set the corresponding theme
Void SetTheme (ComboBoxItem comboBoxItem)
{
If (comboBoxItem! = Null)
{
ControlPage control = new ControlPage ();
Test. Children. Clear ();
Test. Children. Add (control );
Uri uri = new Uri (comboBoxItem. DataContext. ToString (), UriKind. Relative );
ImplicitStyleManager. SetResourceDictionaryUri (control, uri );
ImplicitStyleManager. SetApplyMode (control, ImplicitStylesApplyMode. Auto );
ImplicitStyleManager. Apply (control );
}
}
In the above Code, the ControlPage class is the control page object to be loaded. On this object, declare some controls and then
As a child control, the component (SET) is loaded to the Stack element (Test) on the current PAGE. So let's run this DEMO and take a look.
Display Effect of each topic:
Of course, several theme-making plug-in tools, such as ksung and Colorful Expression, are also officially recommended.
You can get some information from this link :)
Now, the content of today is here first. For source code download, click here.
Link: http://www.cnblogs.com/daizhj/archive/2009/01/19/1378090.html
Author: daizhj, Dai zhenjun
URL: http://daizhj.cnblogs.com/
In Microsoft's Silverlight open-source control project: Silverlight Toolkit