有一个 App.xaml ResourceDictionary.MergedDictionaries 主题只影响某些 WPF 控件
Have a App.xaml ResourceDictionary.MergedDictionaries Theme affect only certain controls WPF
在我的 App.xaml 中,我有以下代码:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- primary color -->
<ResourceDictionary>
<!-- include your primary palette -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Scroll.xaml" />
<ResourceDictionary Source="Styles/ComboBox.xaml" />
<ResourceDictionary Source="Styles/ComboBoxCanType.xaml" />
<ResourceDictionary Source="Styles/ComboBoxCanType1.xaml" />
<ResourceDictionary Source="Styles/ComboBox1.xaml" />
<ResourceDictionary Source="Styles/TextBox.xaml" />
<ResourceDictionary Source="Styles/TaskContextMenu.xaml" />
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.red.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="#E42F34"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="#FFFFFF"/>
<!--<LinearGradientBrush x:Key="PrimaryHueMidBrush" EndPoint="1.5,1.5" StartPoint="0.5,0">
<GradientStop Color="#8E2E2F" Offset="0"/>
<GradientStop Color="#E43D47" Offset="1"/>
</LinearGradientBrush>-->
<!--#F14450-->
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#F14450"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="#FFFFFF"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="#4D1DCF"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="#FFFFFF"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
我想从 HandyControl UI(特别是 WaveProgressBar
)获得一个特定的控件,因此我需要这些行:
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
让它工作并加载控件。但是,如果我这样做,它会扰乱我的 MaterialDesign 控件和我拥有的其他默认控件,那么我如何才能仅为 WaveProgressBar
设置主题?如有任何帮助,我们将不胜感激!
资源有范围。
您可以合并那些只是为了您的控制:
<WaveProgressBar ......>
<WaveProgressBar.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
或者作为包含多个此类控件的网格的资源。
或者作为包含许多此类控件的用户控件的资源。
等等。
话虽如此。
可以针对特定控件应用样式和模板,您似乎在那里有一个独特的控件。
因此,您可以抓取所需的位并将它们置于一种样式中,该样式将模板、属性 值等设置为 WaveProgressBar。这也可能更有效率。
在我的 App.xaml 中,我有以下代码:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- primary color -->
<ResourceDictionary>
<!-- include your primary palette -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Scroll.xaml" />
<ResourceDictionary Source="Styles/ComboBox.xaml" />
<ResourceDictionary Source="Styles/ComboBoxCanType.xaml" />
<ResourceDictionary Source="Styles/ComboBoxCanType1.xaml" />
<ResourceDictionary Source="Styles/ComboBox1.xaml" />
<ResourceDictionary Source="Styles/TextBox.xaml" />
<ResourceDictionary Source="Styles/TaskContextMenu.xaml" />
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.red.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="#E42F34"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="#FFFFFF"/>
<!--<LinearGradientBrush x:Key="PrimaryHueMidBrush" EndPoint="1.5,1.5" StartPoint="0.5,0">
<GradientStop Color="#8E2E2F" Offset="0"/>
<GradientStop Color="#E43D47" Offset="1"/>
</LinearGradientBrush>-->
<!--#F14450-->
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#F14450"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="#FFFFFF"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="#4D1DCF"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="#FFFFFF"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
我想从 HandyControl UI(特别是 WaveProgressBar
)获得一个特定的控件,因此我需要这些行:
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
让它工作并加载控件。但是,如果我这样做,它会扰乱我的 MaterialDesign 控件和我拥有的其他默认控件,那么我如何才能仅为 WaveProgressBar
设置主题?如有任何帮助,我们将不胜感激!
资源有范围。 您可以合并那些只是为了您的控制:
<WaveProgressBar ......>
<WaveProgressBar.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
或者作为包含多个此类控件的网格的资源。 或者作为包含许多此类控件的用户控件的资源。 等等。
话虽如此。
可以针对特定控件应用样式和模板,您似乎在那里有一个独特的控件。 因此,您可以抓取所需的位并将它们置于一种样式中,该样式将模板、属性 值等设置为 WaveProgressBar。这也可能更有效率。