2012-03-12 68 views
0

我想禁用鼠标悬停在我的列表框中的每个项目上的视觉效果, ,我想在用户单击时禁用视觉效果。在鼠标悬停的列表框自定义/禁用选择器(windows8)

我读到它可以使用在Windows Phone上, 但在Windows 8 DataTrigger完成,我们不能使用DataTrigger: DataTrigger in WinRT?

还有什么我可以用它来删除的视觉效果?
我看到了StyleSelector/ListViewItemStyleSelector,我可以使用它吗?
如果是,我可以在哪里找到一个样本,因为我不明白它是如何工作的。

回答

2

如果你的意思是禁用所选项目的风格,那么在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即可。

例如,而不是<ListBox .../>使用<ItemsControl .../>。一个ItemsControl显示一个像列表框这样的项目列表,但没有选定项目的概念。

+0

谢谢,ItemsControl的似乎工作,但一个项目被点击ItemControl作为一个列表框(并且知道女巫项目选择)? – NicoMinsk 2012-03-12 23:13:43

+0

正如我所说'没有选定项目的概念'。没有ItemsControl没有选定的项目。 – Phil 2012-03-13 06:47:13

+0

好吧,我找到了一个解决方案,带有一个按钮,并且使用bindind标签。 – NicoMinsk 2012-03-13 07:11:52

1

如果要编辑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}" />