c# - 缩小所选项目 ListView 的选择区域

标签 c# wpf listview mvvm

我有一个带有按钮的列表 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/

相关文章:

java - Android 抽屉布局显示在 fragment 内容下

asp.net - Response.End 之后关闭窗口

c# - 如何正确地将我的 ContextMenu 命令绑定(bind)到 RelayCommand?

c# - 将 Spring.NET 与 NHibernate 3 一起使用

wpf - 如何在 WPF 中自动调整 GridViewColumn 数据大小并右对齐?

WPF 矩形 - 圆化顶角

c# - 自动调整大小以适合所有内容

c# - 尝试实现自定义格式化程序,但从未调用 ICustomFormatter.Format

c# - 我应该使用 EventArgs 还是简单的数据类型?

c# - 为什么我不能从 GridViewRow PresenterBase 派生?