C# 鼠标悬停在(windows8)上的列表框自定义/禁用选择器
我想在列表框的每个项目上禁用鼠标悬停的视觉效果, 我还想禁用用户单击时的视觉效果 我读到它可以在Windows Phone上使用DataTrigger来完成, 但在Windows 8上,我们不能使用DataTrigger: 我还可以使用什么来删除此视觉效果?C# 鼠标悬停在(windows8)上的列表框自定义/禁用选择器,c#,xaml,windows-8,microsoft-metro,windows-runtime,C#,Xaml,Windows 8,Microsoft Metro,Windows Runtime,我想在列表框的每个项目上禁用鼠标悬停的视觉效果, 我还想禁用用户单击时的视觉效果 我读到它可以在Windows Phone上使用DataTrigger来完成, 但在Windows 8上,我们不能使用DataTrigger: 我还可以使用什么来删除此视觉效果? 我看到了StyleSelector/ListViewItemStyleSelector,我可以使用它吗? 如果是,我在哪里可以找到示例,因为我不了解它是如何工作的。如果您的意思是禁用所选项目样式,那么在WPF中可以执行以下操作: <
我看到了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}" ...>
不幸的是,我还没有访问Windows8的权限,所以我不能说它是否在WinRT上工作
或者,如果您根本不需要任何选择,只需使用ItemsControl
例如,使用
代替
。items控件显示类似列表框的项目列表,但没有选定项目的概念。如果您的意思是禁用选定项目样式,则在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}" ...>
不幸的是,我还没有访问Windows8的权限,所以我不能说它是否在WinRT上工作
或者,如果您根本不需要任何选择,只需使用ItemsControl
例如,使用
代替
。items控件显示类似列表框的项目列表,但没有选定项目的概念。如果要编辑Metro样式应用程序的列表框模板,可以从鼠标或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}" />
如果要编辑Metro样式应用程序的列表框模板,可以从鼠标悬停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}" />
谢谢,itemsControl似乎可以工作,但是否可以像在列表框中一样在ItemControl上单击一个项目(并且知道是否选择了witch项目)?正如我所说的“没有所选项目的概念”。没有ItemsControl没有选择的项目。好的,我找到了一个带有按钮和bindind标记的解决方案。谢谢,ItemsControl似乎可以工作,但是可以像在列表框上一样在ItemControl上单击项目(并且知道选择了哪些项)?正如我说的“没有选择项目的概念”。没有项控件没有选定的项。好的,我找到了一个带有按钮和带有bindind标记的解决方案。