I may have missed something obvious with WPF, but is it possible to create styles that work hierarchically with the targeted control's child controls? To better explain, think of how CSS works to style HTML. You can hierarchically target controls with CSS via selectors:
div > span em
{
color: blue;
}
ul.class > li ul li
{
display: block;
margin: 0px;
}
Is it possible to achieve the same thing with WPF styles? So far, I have been creating styles for every type of control, or named styles that I directly apply to a control. However, I end up with a hell of a lot more styles than I really intend, and I is nearly impossible to style control structures together as a group.
Thanks for any insight.
UPDATE:
Here is an example of what I would like to be able to do. Note that only the root ListView control has a Style applied. I would like to be able to target any one of the child controls in any one of the CellTemplates without having to directly apply the style to each of those child controls. This keeps my view layout markup more decoupled and isolated from the style markup, giving me a lot more freedom to change the style without having to explicitly create a style for every single control in my entire application.
<Grid>
<ListView Style="{StaticResource ProcessableItemsListView}">
<ListView.View>
<GridView>
<GridViewColumn Width="10">
<GridViewColumn.CellTemplate>
<Grid>
<CheckBox Value="{Binging ...}" />
</Grid>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="*">
<GridViewColumn.CellTemplate>
<Grid>
<TextBlock Text="{Binding ...}" />
</Grid>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="80">
<GridViewColumn.CellTemplate>
<Grid>
<Button Command="{Binding ...}">Process</Button>
</Grid>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="120">
<GridViewColumn.CellTemplate>
<Grid>
<ProgressBar Value="{Binding ...}" />
</Grid>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListBiew>
</Grid>