ListView 项目颜色冲突
鼠标悬停和键盘聚焦时项目呈绿色。当鼠标悬停在某些项目上时,如何将所选项目的颜色恢复为白色?
就像我必须分离机制一样。
XAML:
<Window.Resources>
<SolidColorBrush x:Key="ListBorder" Color="Green"/>
<SolidColorBrush x:Key="Brush_ListItem_MO" Color="Green"/>
<SolidColorBrush x:Key="Brush_Tree_Item_Border" Color="Green"/>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid x:Name="container">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition SharedSizeGroup="A" Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border x:Name="Border" Grid.ColumnSpan="3" Height="35"
HorizontalAlignment="Stretch" />
<TextBlock Text="{TemplateBinding Content}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource ListBorder}" />
<Setter Property="Background" TargetName="Border" Value="{DynamicResource Brush_ListItem_MO}" />
<Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource Brush_Tree_Item_Border}" />
<Setter Property="BorderThickness" TargetName="Border" Value="1" />
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource ListBorder}" />
<Setter Property="Background" TargetName="Border" Value="{DynamicResource Brush_ListItem_MO}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true" />
<Condition Property="Selector.IsSelectionActive" Value="false" />
</MultiTrigger.Conditions>
<Setter Property="BorderBrush" TargetName="Border" Value="Red" />
<Setter Property="Background" TargetName="Border" Value="Red" />
<Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource Brush_Tree_Item_Border}" />
<Setter Property="BorderThickness" TargetName="Border" Value="1" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
<!--fgdfgdfgfdgfdgfg-->
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<ListBox >
<ListBox.Items>
<ListBoxItem>1</ListBoxItem>
<ListBoxItem>2</ListBoxItem>
<ListBoxItem>3</ListBoxItem>
<ListBoxItem>4</ListBoxItem>
<ListBoxItem>5</ListBoxItem>
</ListBox.Items>
</ListBox>
</Grid>
Items are colored in green on mouse-over and on keyboard focused. How can i return the colouring of the selected items to white while the mouse is over some item?
it's like I have to separated mechanisms.
XAML:
<Window.Resources>
<SolidColorBrush x:Key="ListBorder" Color="Green"/>
<SolidColorBrush x:Key="Brush_ListItem_MO" Color="Green"/>
<SolidColorBrush x:Key="Brush_Tree_Item_Border" Color="Green"/>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid x:Name="container">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition SharedSizeGroup="A" Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border x:Name="Border" Grid.ColumnSpan="3" Height="35"
HorizontalAlignment="Stretch" />
<TextBlock Text="{TemplateBinding Content}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource ListBorder}" />
<Setter Property="Background" TargetName="Border" Value="{DynamicResource Brush_ListItem_MO}" />
<Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource Brush_Tree_Item_Border}" />
<Setter Property="BorderThickness" TargetName="Border" Value="1" />
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource ListBorder}" />
<Setter Property="Background" TargetName="Border" Value="{DynamicResource Brush_ListItem_MO}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true" />
<Condition Property="Selector.IsSelectionActive" Value="false" />
</MultiTrigger.Conditions>
<Setter Property="BorderBrush" TargetName="Border" Value="Red" />
<Setter Property="Background" TargetName="Border" Value="Red" />
<Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource Brush_Tree_Item_Border}" />
<Setter Property="BorderThickness" TargetName="Border" Value="1" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
<!--fgdfgdfgfdgfdgfg-->
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<ListBox >
<ListBox.Items>
<ListBoxItem>1</ListBoxItem>
<ListBoxItem>2</ListBoxItem>
<ListBoxItem>3</ListBoxItem>
<ListBoxItem>4</ListBoxItem>
<ListBoxItem>5</ListBoxItem>
</ListBox.Items>
</ListBox>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 MultiTrigger 来分离场景。以下是场景:
XAML:
I separated the scenarios using
MultiTrigger
. Following are the scenarios:XAML: