I am trying to apply a custom style to a control whenever it is in a particular state, this style can be set on the object as a style. However, when setting a trigger to do this, the style property cannot be set again:
<Style TargetType="{x:Type ContentPresenter}">
<Style.Triggers>
<Trigger Property="ContentTemplate" Value="{x:Null}">
<Setter Property="Style" Value="{Binding MouseOverGroupStyle, RelativeSource={RelativeSource TemplatedParent}}" />
</Trigger>
</Style.Triggers>
</Style>
Style object is not allowed to affect the Style property of the object to which it applies.
Which makes sense, however, what is the alternative? I cannot bind to the setters list, because it is readonly.
Your solution here is to use a StyleSelector, which takes the ContentPresenter and checks the ContentTemplate.
Unfortunately, ContentPresenter doesn’t have a StyleSelector property to which you can bind a StaticResource of an instance of your ContentTemplateStyleSelector so you may need to cast from ContentPresenter to something which does.
Alternatively, there is the option of using a DataTemplateSelector.