2009-03-17 14 views
0

私はスタイルが新しく、項目を透明な背景にしてから、フォントがゴールドになったときに、フォントをゴールドにするListBoxItemのスタイルを作成するのに役立つ必要があります。クリックしたときに色が変わってはならず、マウスが動かなくなっても正常に戻ります。選択したオブジェクトをListBoxのPreviewMouseRightButtonDownイベントに渡す必要がありますヘルプListBoxItemのスタイルを作成する

私は現在、REUXABLES THEMESのデフォルト辞書を使用していますが、アプリケーション上のこの部分の色を多く塗ります。

おかげで、

<DataTemplate x:Key="ItemsTemplate"> 
     <StackPanel Orientation="Vertical" 
       Margin="0,5,0,5" 
       Width="{Binding 
       Path=ActualWidth, 
       RelativeSource={RelativeSource 
       Mode=FindAncestor, 
       AncestorType={x:Type ScrollContentPresenter}}}" MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, 
       AncestorType={x:Type ScrollViewer}}, Path=ViewportWidth}" > 
      <TextBlock VerticalAlignment="Top" TextWrapping="Wrap" FontSize="14" Text="{Binding Path=CID}" /> 
       <StackPanel Orientation="Horizontal" Margin="0,5,0,0" > 
        <TextBlock> 
         <Label Foreground="{DynamicResource DisabledForegroundBrush}" >Posted by</Label> 
         <Label Foreground="{DynamicResource DisabledForegroundBrush}" VerticalContentAlignment="Top" Content="{Binding Path=ACID}" /> 
        </TextBlock> 
        <TextBlock> 
         <Label Foreground="{DynamicResource DisabledForegroundBrush}" Margin="3,0,0,0">at</Label> 
         <Label Foreground="{DynamicResource DisabledForegroundBrush}" Margin="3,0,3,0" VerticalContentAlignment="Top" Content="{Binding Path=Type}" /> 
        </TextBlock> 
        <TextBlock> 
         <Label Foreground="{DynamicResource DisabledForegroundBrush}">(</Label> 
         <Label Foreground="{DynamicResource DisabledForegroundBrush}" VerticalContentAlignment="Top" Content="{Binding Path=Route}" /> 
         <Label Foreground="{DynamicResource DisabledForegroundBrush}">)</Label> 
        </TextBlock> 
       </StackPanel> 

      </StackPanel> 
    </DataTemplate> 

    <Style x:Key="ItemsListBox" TargetType="{x:Type ListBoxItem}"> 
     <Setter Property="SnapsToDevicePixels" Value="true"/> 
     <Setter Property="Background" Value="{DynamicResource Transparent}"/> 
     <Setter Property="BorderBrush" Value="{DynamicResource Transparent}"/> 
     <Setter Property="BorderBrush" Value="{DynamicResource Transparent}"/> 
     <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> 
    </Style> 

<ListBox x:Name="ListViewFlightPlans" Grid.Column="0" ItemTemplate="{DynamicResource ItemsTemplate}" 
         MaxWidth="800" ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderBrush="Black" BorderThickness="2,0,0,1"> 

      </ListBox> 

デイブ

答えて

1

残念ながら、選択ハイライトとBorderListBoxItemControlTemplateの内部にあることから、ご希望の効果を持っていませんListBoxItemためBorderBrushを変更します。

代わりにSystemColors.HighlightBrushKeyというキーで新しいBrushリソースを追加することができます。これは、選択ハイライトの色の設定に使用するキーです(ListBoxItem)。

非アクティブな選択ブラシのキーはSystemColors.ControlBrushKeyです。したがって、両方を透明なBrushで上書きすると、選択色がないことが保証されます。 this articleで詳細を読むことができます。

は、ここですべてを一例ですが、あなたのDataTemplate

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Grid.Resources> 
     <x:Array x:Key="data" Type="{x:Type sys:String}"> 
      <sys:String>a </sys:String> 
      <sys:String>bb</sys:String> 
      <sys:String>ccc</sys:String> 
      <sys:String>dddd</sys:String> 
     </x:Array> 
    </Grid.Resources> 
    <ListBox ItemsSource="{StaticResource data}"> 
     <ListBox.Resources> 
      <Style TargetType="{x:Type ListBoxItem}"> 
       <Style.Resources> 
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/> 
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/> 
       </Style.Resources> 
       <Style.Triggers> 
        <Trigger Property="IsSelected" Value="True"> 
         <Setter Property="Foreground" Value="Black"/> 
        </Trigger> 
        <Trigger Property="IsMouseOver" Value="True"> 
         <Setter Property="Foreground" Value="Gold"/> 
        </Trigger> 
       </Style.Triggers> 
      </Style> 
     </ListBox.Resources> 
    </ListBox> 
</Grid> 
+0

おかげで、とても素敵な答えと例が完全に働きました。 – user38349

関連する問題