在列表框WPF中为selecteditem设置边框 [英] Set a border around selecteditem in listbox WPF

查看:79
本文介绍了在列表框WPF中为selecteditem设置边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在列表框上设置样式以在所选项目周围添加边框?

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

推荐答案

最简单的方法是在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>

这篇关于在列表框WPF中为selecteditem设置边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆