2012-03-12 71 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}" />