我有一个带有按钮的列表 View 。每当我按下一个按钮时,我都会在 View 模型中获得所选的项目,基于此,我将执行 View 模型操作。我的问题是,如果我在该项目之外单击,按钮也会被选择为矩形区域选择比我的按钮大。
如何缩小与商品尺寸相等的选择区域?
最佳答案
为了直接回答您的问题,大多数集合控件上都有一个属性,该属性使整个行都可以选择,并且我怀疑您可能已经设置了它。如果您已将HorizontalContentAlignment
属性设置为Stretch
,那就是您的问题。删除此属性以删除多余的可选区域。
另外,您可以将其添加到Resources
部分中,以一起删除默认的蓝色,或将其更改为其他颜色:
对于Background
:
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
对于
Foreground
:<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black" />
关于c# - 缩小所选项目 ListView 的选择区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18821875/