我想在我的列表框的每一项上禁用鼠标经过时的视觉效果,我也想在用户单击时禁用视觉效果。
我读到可以在Windows Phone上使用DataTrigger,但在Windows8上,我们不能使用DataTrigger:DataTrigger in WinRT?
我还可以使用什么来删除此视觉效果?
我看到了StyleSelector/ListViewItemStyleSelector,我可以使用它吗?
如果是,我在哪里可以找到样本,因为我不知道它是如何工作的。
发布于 2012-03-13 06:16:29
如果您的意思是禁用所选项目样式,那么在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。
例如,使用<ItemsControl .../>代替<ListBox .../>。ItemsControl显示类似于ListBox的项目列表,但没有所选项目的概念。
发布于 2012-03-15 10:59:18
如果要编辑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}" />https://stackoverflow.com/questions/9675531
复制相似问题