Как применить MaterialDesignInXAML только к одному элементу управления - PullRequest
0 голосов
/ 10 ноября 2019

Я хочу использовать MaterialDesignInXAML для некоторых элементов моего приложения WPF, но я не хочу применять тему ко всем приложениям (меня особенно интересуют кнопки)

Так как жеиспользуйте тему, не применяя ее к App.xaml:

<Application . . . >
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Ответы [ 2 ]

0 голосов
/ 11 ноября 2019

Только ссылки на ресурсы кнопки: MaterialDesignTheme.Button.xaml :

<Application>
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
</Application>

Все стили не являются неявными и должны явно указываться как {StaticResource}. Вы можете проверить исходный файл на GitHub , чтобы узнать, какие стили (ключи) доступны.

0 голосов
/ 10 ноября 2019

Вы должны добавить ResourceDictionary строк в ваши UserControl

<Button x:Class="MyButton">
<Button.Resources>
<ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Button.Resources>
</Button>

и использовать MyButton

<MyButton></MyButton>
...