Set a border around selecteditem in listbox WPF

荒凉一梦 提交于 2019-12-07 06:24:06

问题


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


回答1:


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>



回答2:


FocusVisualStyle may be what are you looking for.



来源:https://stackoverflow.com/questions/4983903/set-a-border-around-selecteditem-in-listbox-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!