In a ListView I bind with a DataTrigger condition the background colour of an Item (textblock) to an Integer property, because when the property changes (from 0 to 1) I want that item's background goes from transparent to red.
This trigger does not works in two cases: when the mouse is over the item, or when this specific item is selected. In these two cases, the background is always transparent, despite of property's value.
So the item change its background only if the mouse is over other differents items, or other items are selected.
The textblock is defined in a separate DataTemplate (it is part of a BoardViewModel), and the ListView is the collection of these VM. In my code I checked that there is no "isMouseOver" active trigger condition in textblock's description and that there is no "isSelected" active trigger in the listview's section. I also tried to delete the background of the structures, but that has no effect with the problem.
--DataTemplate ---
<DataTemplate DataType="{x:Type viewModels:BoardViewModel}">
<Grid >
<Grid HorizontalAlignment="Stretch" Grid.Row="0" Width="Auto" Height="Auto">
<Border Margin="20,20,20,20" BorderThickness="2" BorderBrush="Transparent" HorizontalAlignment="Stretch">
<TextBlock HorizontalAlignment="Stretch">
<TextBlock.Text>
<MultiBinding StringFormat="ID: {0}">
<Binding Path="ID"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Border>
</Grid>
</Grid>
</DataTemplate>
--- View ---
<Grid Grid.Row="0">
<ListView Height="Auto" Background="{StaticResource BoardBackground}" ItemsSource="{Binding Path= BoardViewModels}" SelectedItem="{Binding CurrentBoardViewModel}" IsSynchronizedWithCurrentItem="true">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Path= ErrorRedFlagByBoard}" Value="1">
<Setter Property="Background" Value="Red"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path= ErrorRedFlagByBoard}" Value="0">
<Setter Property="Background" Value="Transparent"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
I checked the correct value of the integer property of the viewmodel, so I expected that item's background remains red also when item is selected or mouse is over the item, but something invalidate this assertion and I do not understand what. Thank you all.