2013-08-21 60 views
0

我在WPF项目中使用MahApps.Metro。但是我没有使用nuget包,而是下载了源代码并将其作为项目添加到我的解决方案中(出于某些原因)。如你所知,它有一个默认主题,用于所有的控件。现在,我试图在我的项目中更改MetroWindow的默认值。我不想改变原来的项目。所以我创建了一个新的ResourceDictionary,我在这方面的风格。我试图改变MetroWindow默认他们,但似乎没有x:Key属性是不可能的。我的意思是我尝试这样做:覆盖WPF UserControl默认主题

<Style TargetType="{x:Type metro:MetroWindow}"> 
    <!-- My styles and templates gone here... --> 
</Style> 

和这一个了:

<Style x:Key="{x:Type metro:MetroWindow}" TargetType="{x:Type metro:MetroWindow}"> 
    <!-- My styles and templates gone here... --> 
</Style> 

但没有他们,就控制和控制仍然使用由MahApps.Metro定义的默认主题效果。我错过了什么?任何想法?它甚至有可能吗?

回答

0

我也试过一样,但事实证明,这是不可能改变窗口样式。你能做到的唯一方法是通过rolling your own window

至于控件,您可以通过使用如改变风格:

<Style TargetType="Button" BasedOn="{StaticResource MetroButton}"> 
    <!-- your changes here --> 
</Style> 
0

另一种方式来做到这一点是创建自己的主题。

  1. 从Mahapps复制BaseLight.xaml或BaseDark.xaml文件的内容并将其粘贴到新的主题文件中。
  2. 覆盖在应用程序启动主题

    protected override void OnStartup(StartupEventArgs e) 
    { 
        base.OnStartup(e); 
    
        // Add and apply style 
        ThemeManager.AddAccent("CustomAccent", new Uri("pack://application:,,,/Custom.Style;component/CustomAccent.xaml")); 
        ThemeManager.AddAppTheme("CustomTheme", new Uri("pack://application:,,,/Customo.Style;component/CustomTheme.xaml")); 
        ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent("CustomAccent"), ThemeManager.GetAppTheme("CustomTheme")); 
    } 
    
  3. 改变所有MetroWindow例如背景颜色,改变的关键值“WhiteColor”