WPF: Changing control style based on the system theme

本文介绍如何为自定义UI控件实现主题依赖的设计方法,包括文件组织结构、样式定义及回退机制等内容。
Usability is an important aspect when it comes to UI design. The emphasis is on the look and feel. So when it comes to creating your own controls it would be good if they look and feel like rest of the apps - theme dependent. A little zing here and there is good :). Making custom controls theme dependent is pretty easy. All you need is a folder named themes inside which you place the theme file containing the control style. The file name should correspond to the theme.

themes/..xaml


      themes/luna.normalcolor.xaml


      themes/luna.homestead.xaml


      themes/luna.metallic.xaml


      themes/royale.normalcolor.xaml


      themes/aero.normalcolor.xaml


      themes/Classic.xaml


 


Also include a generic.xaml file which is the fallback style


The next step is to include an assembly attribute


[assembly:ThemeInfo(ResourceDictionaryLocation.SourceAssembly,                           ResourceDictionaryLocation.SourceAssembly)]


 


The first parameter tell the theme engine to look for the theme ResourceDictionary in the current assembly. The second parameter specifies that there is a generic.xaml file which can be used as a fallback. Compile and Run. Change the themes to see it working :)


 


There is an attached zipped file which shows the same for a custom button :) which functions more like a label ;)  .. looks something like the below ..

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值