- Rocko Bonaparte
- Posts: 39
- Joined:
Setting a ListBox ItemContainerStyles's FocusVisualStyle to Null turns the items purple
This isn't the end of the world (anymore) but I was wondering how defining a style for a ListBoxItem where I turn the FocusVisualStyle Null will turn the whole mess purple. This is despite the items being buttons with a style defined:
So I know I need to define control templates for my controls, but I was kind of surprised how it went down here. Is there a default container style that I didn't sufficiently override when I only set the FocusVisualStyle?
It came up because I've been interacting with some folks that like to get rid of the "marching ants" and I think I agree for what I'm trying to do.
Code: Select all
<ListBox Name="ChoicesList" Background="Transparent" Foreground="White"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectedItem="{Binding SelectedItem}" ItemsSource="{Binding Choices}"
PreviewKeyDown="ChoicesList_PreviewKeyDown">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Button Content="{Binding}" Click="Button_Click" Style="{StaticResource ResourceKey=SaveButtonStyle}" Background="Transparent" Foreground="White" MouseEnter="Button_MouseEnter"/>
</DataTemplate>
</ListBox.ItemTemplate>
<!--
AND HE SHALL DON THE PURPLE! This doesn't seem to be sufficient to define the container style for some reason. It turns the controls purple.
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
</ListBox.ItemContainerStyle>
-->
</ListBox>
It came up because I've been interacting with some folks that like to get rid of the "marching ants" and I think I agree for what I'm trying to do.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Setting a ListBox ItemContainerStyles's FocusVisualStyle to Null turns the items purple
You are missing the BasedOn to extend the application style (that should contain setters for many properties including the Template) with your local style:
Code: Select all
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResoruce {x:Type ListBoxItem}}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
</ListBox.ItemContainerStyle>
Who is online
Users browsing this forum: Google [Bot] and 83 guests