使用Silverlight Toolkit中的主题(Theme)

使用Silverlight Toolkit中的主题(Theme),第1张

概述      在Silverlight Tookit 中提供了大约十种主题,大家可以根据自己的喜好,很容易就在项目中实现 动态换肤效果。当然其官方还推荐了几个制作主题的插件,使用这些 Blend插件可以很方便的生成各种 风格颜色的主题。       好了,下面开始今天的正文。           首先我们要下载该Tookit并将其中的相应DLL文件:Microsoft.Windows.Control

      在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  Content ="CheckBox" />
        
< Radiobutton  Content ="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);
    
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);
}

// 设置相应的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);
    }
}

 

     上面代码中的ControlPage 类即是我们要加载的控件页对象,在该对象上声明了一些控件,然后将这些控
件(集合)做为子控件加载到当前PAGE页面中的Stack元素(Test)中。这样我们运行一下这个DEMO,看一下
各个主题的显示效果:

     
  

      
      
 
 

           

    
 

      
      
   
    
 

           
      

    
 

            
   
    
  

      
      
    
    
  

      
  
    
  

      
  
    
  

      
      
 
  

   

     当然,官方还推荐了几个主题制作插件工具,比如: Kuler,以及插件colorful Expression。
可以从这个链接中获得一些信息:)  
   

     好了,今天的内容就先到这里了,源码下载,请点击这里。
   
     原文链接:http://www.cnblogs.com/daizhj/archive/2009/01/19/1378090.html

     作者: daizhj,代震军

     Tags: silverlight,theme,toolkit,风格

     网址: http://daizhj.cnblogs.com/
   
     在微软的Silverlight 开源控件项目: Silverlight Toolkit

总结

以上是内存溢出为你收集整理的使用Silverlight Toolkit中的主题(Theme)全部内容,希望文章能够帮你解决使用Silverlight Toolkit中的主题(Theme)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1061968.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存