Reputation: 2442
I am creating a custom control in WPF and would like to have my converters in a separate resource dictionary to make things cleaner. I have a ControlStyling.xaml
resource dictionary for the styling of my controls
<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>
A Converters.xaml
resource dictionary where I would like to keep my 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"/>
And the Themes/Generic.xaml where I am pointing to both of these dictionaries.
<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>
The problem I am having is when I place my converters in a separate resource dictionary my ControlStyling.xaml
dictionary doesn't have a reference to the converters (which seems obvious now that I think about it). I thought that I would be able to use these converters since I merged both dictionaries in my Themes/Generic.xaml
dictionary but that didn't work. Is there a good way to have all my converters in a separate dictionary and still be able to reference them in my ControlStyling.xaml
for this custom control?
Upvotes: 1
Views: 664
Reputation: 5498
Reference the converter resource dictionary from the styling dictionary:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/DialIndicatorControl;component/Themes/Generic/Converters.xaml"/>
</ResourceDictionary.MergedDictionaries>
Upvotes: 2