How can I strike through all textblocks inside my WPF listview? Right now I’ve defined a style that I have to apply to each textblock. It looks like this
<Style x:Key="orderDetailsTextBlock" TargetType="TextBlock" >
<Style.Triggers>
<DataTrigger Binding="{Binding Status}" Value="Failed">
<Setter Property="TextDecorations" Value="Strikethrough" />
</DataTrigger>
</Style.Triggers>
</Style>
What I want is to be able to apply this once inside the ListViewItem Style block.
I tried to do it like this
<Style x:Key="ordersListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding Status}" Value="Failed">
<Setter Property="TextBlock.TextDecorations" Value="Strikethrough" />
</DataTrigger>
</Style.Triggers>
</Style>
But this doesn’t work. Any help will appreciated.
Update
I updated the ListView’s XAML as follows
<ListView x:Name="orderDetails" AlternationCount="2" ItemContainerStyle="{StaticResource ordersListViewItemStyle}" >
<ListView.Resources>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Status}" Value="Failed">
<Setter Property="TextDecorations" Value="Strikethrough" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn Width="100" Header="Статус" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock
Text="{Binding Path=Status, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
ToolTip="{Binding Path=Message, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Nothing happens. What have I done wrong?
You can define the Style inside your
ListView.Resourceswithout aKey, and it’s scope will be restricted to allTextBlocks inside that particularListView.For instance: