Set border around selected item in WPF list

How to set a style in a list to get a border around a selected item?

+5
source share
2 answers

The easiest way is to add a trigger for IsSelectedin ItemContainerStyle forListBox

<ListBox ...>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="BorderBrush" Value="Red"/>
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="BorderThickness" Value="1"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </ListBox.ItemContainerStyle>
    <!--...-->
</ListBox>
+14
source

FocusVisualStyle may be what you are looking for.

+2
source

All Articles