Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a border around selecteditem in listbox WPF

How do i set a style on the listbox to get a border around the selected item ?

like image 943
syncis Avatar asked Feb 13 '11 11:02

syncis


2 Answers

The easiest way is to add a Trigger for IsSelected in the ItemContainerStyle for the ListBox

<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>
like image 185
Fredrik Hedblad Avatar answered Nov 06 '22 04:11

Fredrik Hedblad


FocusVisualStyle may be what are you looking for.

like image 39
Matěj Zábský Avatar answered Nov 06 '22 03:11

Matěj Zábský