An entry in my Application.Resources
ResourceDictionary
is a control template that, slimmed down, looks similar to the following:
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border>
<Border.BorderBrush>
<SolidColorBrush Color="{Binding Path=BorderColor, RelativeSource={RelativeSource AncestorType=UserControl}" />
</Border.BorderBrush>
</Border>
</ControlTemplate>
Each UserControl
has its own property BorderColor
which this pulls from. In this example, the binding fails to find the property.
Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.UserControl', AncestorLevel='1''.
However, it works in another entry in the dictionary:
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="BorderBrush" Value="{Binding Path=BorderColor, RelativeSource={RelativeSource AncestorType=UserControl}"/>
</Style>
How can I fix the binding in the first example? Preferably I would like to not need additional properties on the instance of each control in the user control.