包含自定义主题设置的WPF主题

时间:2017-03-24 00:58:36

标签: c# .net wpf xaml

我想在我的应用程序上实现主题支持。我知道如何通过在外部程序集上使用ResourceDictionaries并在运行时应用它们,但我想启用使用自定义主题设置和/或颜色托盘的主题。我不知道最好的方法是什么。

我的想法是能够使用这样的标记来声明主题:

<Theme Name="MyTheme" 
       Description="Simple example theme" 
       Icon="MyTheme.ico" 
       Thumbnail="thumbnail.png">
    <Theme.Settings>
        <Setting Key="EnableShadows" Text="Enable theme shadows" Type="{x:Type system:Boolean}" Value="True"/>
    </Theme.Settings>
    <Theme.Resources>
       <ResourceDictionary>
           <ResourceDictionary.MergedDictionaries>
               <ResourceDictionary Source="MyTheme.xaml"/>
           </ResourceDictionary.MergedDictionaries>
       </ResourceDictionary>
    </Theme.Resources>
</Theme>

嗯,这段代码只是一种可行的方式。我的问题是如何在WPF中做这样的事情(如何创建一个可以这种方式用作主题的Theme类)。

1 个答案:

答案 0 :(得分:0)

WPF中的主题是一个非常重要的交易,不会在stackoverflow上被讨论...需要花费很多专业组件,如mahappswpf toolkitapplication。祝好运