MahApps风格不适用于所有项目

时间:2012-11-13 09:27:11

标签: wpf xaml mahapps.metro

我注意到将MahApps.Metro样式添加到我的资源字典时,这些样式将应用于我的应用程序中的所有项目,这不是所需的效果。我只想使用ToggleSwitch和Combobox样式。如何实现这一目标?

感谢名单!

1 个答案:

答案 0 :(得分:4)

在您的xaml

中只放置以下资源词典
<ResourceDictionary>
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Buttons.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.ComboBox.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
  </ResourceDictionary.MergedDictionaries>

  <Style TargetType="ToggleButton" BasedOn="{StaticResource MetroToggleButton}" />
  <Style TargetType="ComboBox" BasedOn="{StaticResource MetroComboBox}" />
  <Style TargetType="ComboBoxItem" BasedOn="{StaticResource MetroComboBoxItem}" />
</ResourceDictionary>

希望这会有所帮助