I'm trying to get a style to apply another style to elements of a certain type. Similar to CSS where you would do
div a
{
background-color:red;
}
To apply a red background to all <a> elements that are contained by <div> elements.
Specifically, I'm trying to get all TableCells contained within a TableRowGroup with a certain style to have their borders changed.
I have the following solution where each cell style is set individually.
<Table>
<Table.Columns>
<TableColumn/>
<TableColumn/>
</Table.Columns>
<Table.Resources>
<Style x:Key="HeaderStyle" TargetType="{x:Type TableRowGroup}">
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="12"/>
</Style>
<Style x:Key="HeaderCellStyle" TargetType="{x:Type TableCell}">
<Setter Property="BorderThickness" Value="0,1,0,1" />
<Setter Property="BorderBrush" Value="Black" />
</Style>
</Table.Resources>
<TableRowGroup Name="TableColumnHeaders" Style="{StaticResource HeaderStyle}">
<TableRow>
<TableCell Style="{StaticResource HeaderCellStyle}">
<Paragraph>
Description
</Paragraph>
</TableCell>
<TableCell Style="{StaticResource HeaderCellStyle}">
<Paragraph>
Amount
</Paragraph>
</TableCell>
</TableRow>
</TableRowGroup>
</Table>
This is clearly not preferred as it bloats the xaml when there are many cells.
I've tried the following with no success.
<Table.Resources>
<Style x:Key="HeaderStyle" TargetType="{x:Type TableRowGroup}">
<Style.Resources>
<Style TargetType="{x:Type TableCell}">
<Setter Property="BorderThickness" Value="0,1,0,1" />
<Setter Property="BorderBrush" Value="Black" />
</Style>
</Style.Resources>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="12"/>
</Style>
</Table.Resources>
This also doesn't work for some reason, though is valid
<Table.Resources>
<Style x:Key="HeaderStyle" TargetType="{x:Type TableRowGroup}">
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="TableCell.BorderThickness" Value="0,1,0,1" />
<Setter Property="TableCell.BorderBrush" Value="Black" />
</Style>
</Table.Resources>
There's going to be a few row groups each with their own cell style and each containing many cells. Please tell me there's a better way.