I need some help here. I can't understand why none of the solutions I found work for my case. Let's consider a Listview with these items:
<ListView.Items>
<ListViewItem>
<TextBlock xml:space="preserve"> 1 <Bold>I'm bold</Bold> </TextBlock>
</ListViewItem>
<ListViewItem>
<TextBlock xml:space="preserve"> 2 Im not </TextBlock>
</ListViewItem>
</ListView.Items>
Initially on hover each row I saw the highlight of the TextBlock in its default light blue. It only underlined the area with text:
I don't want that highlight I want the one of the whole row, and I want to decide the colour. I also want the highlight of the whole row when selecting:
I've been playing with Styles, Triggers or the ItemContainerStyle. I realized that I have to consider the background of the Textbox, and the one of the ListViewItem for the area with text. And the background of the whole row seems to be a business of the ListView.ItemContainerStyle.
The result of adding a style fot the TextBox:
<Style x:Key="TextBlockStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Black" />
<Setter Property="Background" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
<ListView Grid.Column="1" Margin="0" HorizontalContentAlignment="Stretch" BorderThickness="0" >
<ListView.Resources>
<Style BasedOn="{StaticResource TextBlockStyle}" TargetType="{x:Type TextBlock}" />
</ListView.Resources>
is:
Then I add another style to try to get rid of the ListView background under the TextBox:
<Style x:Key="ListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Gold" />
</Trigger>
</Style.Triggers>
</Style>
<ListView Grid.Column="1" Margin="0" HorizontalContentAlignment="Stretch" BorderThickness="0" >
<ListView.Resources>
<Style BasedOn="{StaticResource TextBlockStyle}" TargetType="{x:Type TextBlock}" />
<Style BasedOn="{StaticResource ListViewItemStyle}" TargetType="{x:Type ListViewItem}" />
</ListView.Resources>
But this has no effect at all.
And trying to highlight the whole row with this doesn't work:
<ItemsControl.ItemContainerStyle>
<Style>
<Style.Triggers>
<Trigger Property="Control.IsMouseOver" Value="True">
<Setter Property="Control.Background" Value="Gold" />
</Trigger>
</Style.Triggers>
</Style>
</ItemsControl.ItemContainerStyle>
And tried several other suggestions for hours. This one:
Remove the mouse over effect on a ListView in WPF avoids the highlight over the text on hover,both for the TextBox and the ListViewItem, but I don't know how to change then the background of the whole row.
Could someone provide an example of what I'm trying to do?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…