Rocko Bonaparte
Topic Author
Posts: 30
Joined: 13 Oct 2020, 08:32

Setting a ListBox ItemContainerStyles's FocusVisualStyle to Null turns the items purple

05 Feb 2021, 12:29

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:
<ListBox Name="ChoicesList"  Background="Transparent" Foreground="White" 
            ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"
            SelectedItem="{Binding SelectedItem}" ItemsSource="{Binding Choices}"
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Content="{Binding}" Click="Button_Click" Style="{StaticResource ResourceKey=SaveButtonStyle}" Background="Transparent" Foreground="White" MouseEnter="Button_MouseEnter"/>
        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.
        <Style TargetType="ListBoxItem">
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
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.

User avatar
Site Admin
Posts: 2254
Joined: 22 Dec 2011, 19:20

Re: Setting a ListBox ItemContainerStyles's FocusVisualStyle to Null turns the items purple

05 Feb 2021, 17:06

You are missing the BasedOn to extend the application style (that should contain setters for many properties including the Template) with your local style:
    <Style TargetType="ListBoxItem" BasedOn="{StaticResoruce {x:Type ListBoxItem}}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />

Who is online

Users browsing this forum: No registered users and 2 guests