2012-08-24 110 views
0

我需要幫助來更改SurfaceListBox選擇的顏色。WPF使用SurfaceListBox - 高亮顏色選擇

現在進出口使用此:

<Style x:Key="styleSurfaceListBox" TargetType="{x:Type my:SurfaceListBox}"> 
    <Setter Property="ItemsPanel"> 
     <Setter.Value> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Horizontal" 
       VerticalAlignment="Center" 
       HorizontalAlignment="Center" 
       Background="Transparent" />       
      </ItemsPanelTemplate> 
     </Setter.Value> 
    </Setter>    
</Style> 

我需要做出選擇的顏色transparente?

+0

您可以在這裏找到答案[here](http://stackoverflow.com/questions/794792/wpf-listbox-selection-color) – dvvrd

+0

非常感謝!這是完美的!!! –

回答

0

感謝dvvrd!

創建我SurfaceListBoxItem的風格是這樣的:

 <Style x:Key="item" TargetType="{x:Type my:SurfaceListBoxItem}" > 
     <Style.Triggers> 
      <Trigger Property="IsSelected" Value="true"> 
       <Setter Property="Foreground" Value="Transparent" /> 
       <Setter Property="Background" Value="Transparent" /> 
      </Trigger> 
      <Trigger Property="IsFocused" Value="true"> 
       <Setter Property="Foreground" Value="Transparent" /> 
       <Setter Property="Background" Value="Transparent" /> 
      </Trigger> 

      <Trigger Property="IsEnabled" Value="true"> 
       <Setter Property="Foreground" Value="Transparent" /> 
       <Setter Property="Background" Value="Transparent" /> 
      </Trigger> 
      <Trigger Property="IsMouseOver" Value="true"> 
       <Setter Property="Foreground" Value="Transparent" /> 
       <Setter Property="Background" Value="Transparent" /> 
      </Trigger>     
     </Style.Triggers> 
    </Style> 

然後我將它指向ItemContainerStyle:再次

SurfaceListBox1.ItemContainerStyle = (Style)this.Resources["item"]; //item is the KEY on my style. 

感謝dvvrd!