Applying TextDecoration to an WPF ListViewItem
I can see how to apply a text decoration to a GridViewColumn.
<GridViewColumn Header="Tool" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Entity.ToolId}" TextDecorations="{Binding Path=TextDecoration}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
But if I want the TextDecoration to apply to the entire row (in my case a strikethrough), then I have to duplicate the above code to every GridViewColumn.
What I can not figure out is how to ap开发者_开发问答ply the TextDecoration to the entire listview item possibly via the ItemContainerStyle.
Can anyone give me a head up on how this could be done?
You should not define the binding per column, if the cells of each column support TextDecoration, because then you need to repeat it for every column. Better apply it to DataGrid.CellStyle property:
<DataGrid.CellStyle>
<Style TargetType="TextBlock">
<Setter Property="TextDecorations"
Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}},
Path =Item.TextDecoration}" />
</Style>
</DataGrid.CellStyle>
The challenge here is to access the property TextDecoration. Use relative source binding to find the parent DataGridRow which has an Item property which contains the data for that row.
Formatting WPF DataGrid using binding can be rather perplexing. See my article on CodeProject where I cover the most important cases, including applying TextDecoration on single cells (or all cells in your case): Guide to WPF DataGrid Formatting Using Bindings
use GridViewRow.CellTemplate
精彩评论