I have two controls that contain identical markup, except that they require different converters.
LeftHeader.xaml snippet:
<Path.RenderTransform>
<RotateTransform Angle="{Binding IsToggled, Converter={x:Static local:LeftHeader.GlyphAngleConverter}}"/>
</Path.RenderTransform>
RightHeader.xaml snippet:
<Path.RenderTransform>
<RotateTransform Angle="{Binding IsToggled, Converter={x:Static local:RightHeader.GlyphAngleConverter}}"/>
</Path.RenderTransform>
I thought I could create a UserControl
with a DependencyProperty
of type IValueConverter
called "GlyphAngleConverter"
and this markup:
<UserControl x:Class="GlyphControl"
<UserControl.Template>
<ControlTemplate>
...
<Path.RenderTransform>
<RotateTransform Angle="{Binding IsToggled, Converter={TemplateBinding GlyphAngleConverter}}"/>
</Path.RenderTransform>
...
</ControlTemplate>
</UserControl.Template>
</UserControl>
The header controls would then use the new control and set GlyphAngleConverter
basically like they used before:
New LeftHeader.xaml snippet:
<GlyphControl GlyphAngleConverter="{Binding Source={x:Static local:LeftHeader.GlyphAngleConverter}}"/>
New RightHeader.xaml snippet:
<GlyphControl GlyphAngleConverter="{Binding Source={x:Static local:RightHeader.GlyphAngleConverter}}"/>
But I get the exception "Unable to cast object of type 'System.Windows.TemplateBindingExpression' to type 'System.Windows.Data.IValueConverter'."
What am I doing wrong and/or is there a better approach?