0
我正在WPF中創建自定義控件,並希望將我的轉換器放在單獨的資源字典中以使事情更加清潔。我有我的控制WPF自定義控件中的類型轉換器
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DialIndicatorControl">
<Style TargetType="{x:Type local:MyDialIndicator}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MyDialIndicator}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Ellipse Width="{TemplateBinding BackgroundSizeRadius}"
</Ellipse>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
一個Converters.xaml
資源字典,我想保持我的converteres
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DialIndicatorControl">
<local:RadiusDiameterConverter x:Key="RadiusConvert"/>
而且主題的造型一ControlStyling.xaml
資源字典/ Generic.xaml,我指向這兩個字典。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DialIndicatorControl">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/DialIndicatorControl;component/Themes/Generic/Converters.xaml"/>
<ResourceDictionary Source="/DialIndicatorControl;component/Themes/Generic/ControlStyling.xaml"/>
</ResourceDictionary.MergedDictionaries>
我遇到的問題是,當我把我的轉換器在單獨的資源詞典我ControlStyling.xaml
字典不具有對轉換器的引用(現在,我想它似乎很明顯)。我認爲我能夠使用這些轉換器,因爲我合併了我的Themes/Generic.xaml
字典中的兩個字典,但沒有奏效。是否有一種很好的方法可以將我的所有轉換器放在單獨的字典中,並且仍然可以在我的ControlStyling.xaml
中參考這個自定義控件?