I'm trying to define a hierarchy of button styles and I'd like to be able to set property values in the derived style without losing the Content value set in a
parent Style.
What I have tried:
Here's the simplified "root" Style:
<Style x:Key="CircleButtonStyle"
TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Ellipse x:Name="Circle"
StrokeThickness="0"
Stretch="Uniform"
Fill="{StaticResource myCustomBrush}" />
<ContentPresenter HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Here's the simplified first
derived style:
<Style x:Key="CircleCrossStyle"
TargetType="{x:Type Button}"
BasedOn="{StaticResource CircleButtonStyle}">
<Setter Property="Content">
<Setter.Value>
<Grid>
<Path Stroke="White"
Stretch="Uniform"
Margin="0.5"
Data="M 1 1 H 0 M 1 1 H 2 M 1 1 V 0 M 1 1 V 2"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" />
</Grid>
</Setter.Value>
</Setter>
</Style>
The above worked. Now I want to have a Style that is the same except for rotating the whole thing 45°. I tried:
<Style x:Key="CircleXStyle"
TargetType="{x:Type Button}"
BasedOn="{StaticResource CircleCrossStyle}">
<Setter Property="RenderTransformOrigin"
Value="0.5,0.5" />
<Setter Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="45" />
</Setter.Value>
</Setter>
</Style>
I'm not sure why this didn't work, but it didn't show the Path at all.
I removed the Setters and using this Style still didn't show the Path.
How do I preserve/propagate the Content set in the CircleCrossStyle so I can add the rotation effect in the CircleXStyle? (Or is it impossible using only Styles?)
More exploring:
I was using this on a button in a DataGridTemplateColumn.CellTemplate. I tried referencing the CircleCrossStyle instead. This Style is also used on a button below the DataGrid. When I did this, the CircleCrossStyle was correctly used
only on the last row of the grid!
And the other button that used the style now showed with the path missing, like all of the
other rows of the DataGrid!
I changed the style back to CircleXStyle with no Setters and it behaved exactly the same. Only the last row had the CircleCrossStyle and the other button had only the circle. (I hadn't noticed this before, apparently.)
I tried copying the same Content Setter from CircleCrossStyle to CircleXStyle and changed it to derive from CircleButtonStyle. (So it is identical to CircleCrossStyle except for the name.) Again, only the last row of the Grid is correct.
Any thoughts?