鼠标悬停在(windows8)上的列表框自定义/禁用选择器
本文关键字:自定义 选择器 列表 悬停 windows8 鼠标 | 更新日期: 2023-09-27 18:27:28
我想在列表框的每个项目上禁用鼠标悬停的视觉效果,我也想禁用用户点击时的视觉效果。
我读到它可以在Windows Phone上使用DataTrigger来完成,但在Windows8上,我们不能使用DataTrigger:WinRT中的DataTrigger?
我还能用什么来删除这种视觉效果
我看到了StyleSelector/ListViewItemStyleSelector,我可以使用它吗
如果是,我在哪里可以找到样本,因为我不知道它是如何工作的。
如果你的意思是禁用所选项目样式,那么在WPF中你可以这样做:
<Style x:Key="NullSelectionStyle" TargetType="ListBoxItem">
<Style.Resources>
<!-- SelectedItem with focus -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<!-- SelectedItem without focus -->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
<!-- SelectedItem text foreground -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="{DynamicResource {x:Static SystemColors.ControlTextColorKey}}" />
</Style.Resources>
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
<ListBox ItemContainerStyle="{StaticResource NullSelectionStyle}" ...>
不幸的是,我还没有访问Windows 8,所以我不能说它是否在WinRT上运行。
或者,如果您根本不需要任何选择,只需使用ItemsControl即可。
例如,使用<ItemsControl .../>
代替<ListBox .../>
。ItemsControl显示类似ListBox的项目列表,但没有所选项目的概念。
如果您想编辑Metro Style应用程序的ListBox模板,可以从MouseOver VisualState中删除动画。这里有一个ListBoxItem模板,可以工作。
<Style x:Key="NoSelectListBoxItemStyle" TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Disabled">
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ContentContainer">
<SplineDoubleKeyFrame KeyTime="0" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Selected"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{StaticResource Dark_Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" d:LayoutOverrides="Width"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
并应用样式
<ListBox ItemContainerStyle="{StaticResource NoSelectListBoxItemStyle}" />