2009-03-23 32 views
3

私は基本的にこのようなListBoxをラップUserControlを持っている -WPF - FocusVisualStyleどこに適用しますか?

 <ListBox x:Name="lb" ItemsSource="{Binding ElementName=UC,Path=Pages}" 
      Background="{Binding ElementName=UC,Path=Background}" 
      BorderBrush="Transparent" 
      ScrollViewer.CanContentScroll="False" 
      ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
      ScrollViewer.VerticalScrollBarVisibility="Disabled"> 

     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Horizontal" IsItemsHost="True"/> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 

     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <Grid Width="{Binding ElementName=UC,Path=ActualWidth}"> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition MinWidth="20"/> 
         <ColumnDefinition/> 
         <ColumnDefinition MinWidth="20"/> 
        </Grid.ColumnDefinitions> 
        <ContentPresenter Grid.Column="1" Content="{Binding}"/> 
       </Grid> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 

私は、この機能を非表示にするFocusVisualStyle{x:Null}に設定する必要がありますが、私はそれを適用するに関係なく、私はまだ、デフォルト青選択色を取得します。私はリストボックス、StackPanelとグリッドでそれを設定しようとしたが、役に立たない。

助けがあれば助かります。ありがとう。

答えて

9

FocusVisualStyleは、背景色ではなく、フォーカスされた要素の周りに「行進するアリ」を適用します。

<ListBox> 
    <ListBox.Resources> 
     <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Value="Red"/> 
     <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Value="Black"/> 
    </ListBox.Resources>  
</ListBox> 
2

ケントはFocusVisualStyleのみタブキーでコントロールを選択したキーボード・フォーカス、に関連している正しい:選択しListBoxItemsの背景色を変更するには、ような何かを行います。

あなただけの任意の選択機能せずにリストを表示しようとしている場合は、あなただけのItemsControl

<ItemsControl x:Name="lb" ItemsSource="{Binding ElementName=UC,Path=Pages}" 
    Background="{Binding ElementName=UC,Path=Background}" 
    BorderBrush="Transparent" ScrollViewer.CanContentScroll="False" 
    ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
    ScrollViewer.VerticalScrollBarVisibility="Disabled"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <StackPanel Orientation="Horizontal" IsItemsHost="True"/> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <!-- others --> 
</ItemsControl> 
+0

ジャにあなたのListBoxをダウングレードすることができるかもしれ、それで行くが、私は中のUIElementをレンダリングしていましたListBoxであり、ItemsControl内のItemTemplateには奇妙なことに従わない。しかし、助けてくれてありがとう。 – Stimul8d

関連する問題