2009-03-23 2 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}에 설정해야, 난 여전히 기본 파란색 선택 색상을 얻을. ListBox, StackPanel 및 Grid에서 설정하려고했지만 아무 소용이 없습니다.

도움이 될 것입니다. 감사.

답변

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

응에 목록 상자를 다운 그레이드 할 수 있습니다하는 그와 함께 이동하지만 난에 UiElements의 렌더링있어했다 ListBox 그리고 그들은 이상하게 ItemControl의 ItemTemplate을 따르지 않습니다. 그래도 도움을 주셔서 감사합니다. – Stimul8d

관련 문제