我希望有人能澄清我下面的情況。
我有一個基于名為 SHButtonStyle.xaml 的 ResourceDictionary 中的按鈕的簡單 CustomControl 樣式
<Style TargetType="{x:Type local:SHButton}">
<Setter Property="Background" Value="{StaticResource ResourceKey= Background}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:SHButton}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我還有一個名為 Brushes 的 ResourceDictionary,如下所示:
<SolidColorBrush x:Key="Background" Color="Red"/>
我還有一個帶有 Generic.xaml 的 Themes 檔案夾,其中包含 MergedDictionaries,如下所示:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/TestCustomControl;component/SHButtonStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
我嘗試在 Generic.xaml 中合并畫筆的 ResourceDictionary,因為我理解最好在 Generic.xaml 中合并所有 ResourceDictionary?
但我可以讓它作業的唯一方法是在 SHButtonStyle.xaml 中為畫筆使用額外的 MergedDictionaries。這是正確的還是我在 Generic.xaml 中合并 ResourceDictionary 時遺漏了什么。
預先感謝您的幫助
uj5u.com熱心網友回復:
要么直接合并 theme/generic.xaml 中的筆刷資源字典,要么在全域級別合并它們App.xaml:
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/TestCustomControl;component/Brushes.xaml"/>
<ResourceDictionary Source="/TestCustomControl;component/themes/generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
在MergedDictionaries主題/ generic.xaml通常包含自定義控制元件沒有其他資源字典任何依賴于資源的“獨立”的資源字典。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/315341.html
