I content control "MyControl" and this has a property "GlobalBackground". For the items I have a style like this.
<ControlTemplate x:Key="XTemplate" TargetType="{x:Type local:MyControlItem}">
<Grid HorizontalAlignment="Stretch">
<Rectangle Height="2" Fill="{Binding GlobalBackground, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:MyControl}}"/>
...
</Grid>
</ControlTemplate>
<Style x:Key="XStyle" TargetType="{x:Type local:MyControlItem}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Template" Value="{StaticResource XTemplate}"/>
</Style>
This works as expected.
Now I want to use the same template bound to different properties of the Itemscontrol. So the idea is to set a property via setter (Style Triggers) When I do this
<ControlTemplate x:Key="XTemplate" TargetType="{x:Type local:MyControlItem}">
<Grid HorizontalAlignment="Stretch">
<Rectangle Height="2" Fill="{TemplateBinding Background}"/>
...
</Grid>
</ControlTemplate>
<Style x:Key="XStyle" TargetType="{x:Type local:MyControlItem}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Background" Value="{Binding GlobalBackground, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:MyControl}}" />
<Setter Property="Template" Value="{StaticResource XTemplate}"/>
</Style>
the binding fails.
Is there no way to use FindAncestor bindings in a style setter or am I just doing something wrong?
Manfred