微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Silverlight Toolkit中的主题(Theme)

 在Silverlight Tookit 中提供了大约十种主题,大家可以根据自己的喜好,很容易就在项目中实现
动态换肤效果。当然其官方还推荐了几个制作主题插件,使用这些 Blend插件可以很方便的生成
格颜色的主题

      好了,下面开始今天的正文。
    
     首先我们要下载该Tookit并将其中的相应DLL文件:Microsoft.Windows.Controls.Theming.dll加
到当前的示例中,另外就是相关的theme文件了,我已将10种主题文件放在了这个DEMO的themes 
文件下:

    

   

        并以“内容”方式作为"生成操作"的选项,如下:

    

 

        我们可以直接在XAML文件中声明使用主题的元素,比如:

复制代码

< UserControl 

..
xmlns:theming
="clr-namespace:Microsoft.Windows.Controls.Theming;assembly=Microsoft.Windows.Controls.Theming"

>
    
<!-- ShinyDarkPurple -->
StackPanel  Width ="100"
  theming:ImplicitStyleManager.ApplyMode
="Auto"    
  theming:ImplicitStyleManager.ResourceDictionaryUri
="themes/ExpressionLight.xaml"
        
Button  Content ="Button" /> CheckBox  ="CheckBox" RadioButton  ="RadioButton" Slider ListBox ProgressBar  Height ="15"  Value ="30" controls:Expander  ExpandDirection ="Down"
    
</ StackPanel ShinyDarkGreen UserControl

复制代码

    
    这样在该StackPanel下的所有控件样式均应用了ExpressionLight主题。另外我们也可以在CS
文件中对指定的控件设置相应的主题,比如本DEMO中所写的代码

public  Page()
{
    InitializeComponent();
    
this .ThemeList.SelectionChanged  +=   new  SelectionChangedEventHandler(ThemeList_SelectionChanged);
    
.Loaded   RoutedEventHandler(Page_Loaded);
}

void  Page_Loaded( object  sender, RoutedEventArgs e)
{
    ThemeList.Items.Add(
 ComboBoxItem() { Name  =   " ExpressionDark " , Content  themes/ExpressionDark.xaml true  });
    ThemeList.Items.Add(
ExpressionLight themes/ExpressionLight.xaml RainierOrange themes/RainierOrange.xaml RainierPurple themes/RainierPurple.xaml RainierRadialBlue themes/RainierRadialBlue.xaml ShinyBlue themes/ShinyBlue.xaml ShinyDarkGreen themes/ShinyDarkGreen.xaml ShinyDarkPurple themes/ShinyDarkPurple.xaml ShinyDarkteal themes/ShinyDarkteal.xaml ShinyRed themes/ShinyRed.xaml  });

    SetTheme(ThemeList.Items[
0 as  ComboBoxItem);
}

private  ThemeList_SelectionChanged( // 设置相应的theme  SetTheme(ComboBoxItem comboBoxItem)
{
    
if  (comboBoxItem  != null )
    {
        ControlPage control 
 ControlPage();
        Test.Children.Clear();
        Test.Children.Add(control);

        Uri uri 
 Uri(comboBoxItem.DataContext.ToString(), UriKind.Relative);
        ImplicitStyleManager.SetResourceDictionaryUri(control, uri);
        ImplicitStyleManager.SetApplyMode(control, ImplicitStylesApplyMode.Auto);
        ImplicitStyleManager.Apply(control);
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐