在WPF用户控件中为选定项目实现图形的最佳方法是什么?

时间:2022-11-27 14:27:36

I have implemented a few different WPF user controls. In doing so I have also implemented a few different ways of implementing the graphics for when an item is selected.

我已经实现了一些不同的WPF用户控件。在这样做的过程中,我还实现了几种不同的方式来实现选择项目时的图形。

I want to find out how others are doing this and what they think is the best way of doing it?

我想知道其他人是如何做到这一点的,以及他们认为最好的做法是什么?

Only one solution per answer please.

每个答案只有一个解决方案。

To avoid confusion here are some examples of graphics to indicate that an item is selected:

为了避免混淆,这里有一些图形示例表明选择了一个项目:

  • Adding graphics to the adorner layer for an element.
  • 将图形添加到元素的装饰层。

  • Changing the color of an element based on an 'IsSelected' property in the data.
  • 根据数据中的“IsSelected”属性更改元素的颜色。

  • Procedurally showing/hiding an element in the XAML that indicates selection.
  • 在XAML中以程序方式显示/隐藏指示选择的元素。

1 个解决方案

#1


What do you mean by "implementing the graphics"? Usually an item is rendered with a background of SystemColors.HighlightBrush when it's selected. Any system other than that can be hard to understand for normal users.

“实现图形”是什么意思?通常,项目在选中时会以SystemColors.HighlightBrush的背景呈现。对于普通用户来说,除此之外的任何系统都很难理解。

#1


What do you mean by "implementing the graphics"? Usually an item is rendered with a background of SystemColors.HighlightBrush when it's selected. Any system other than that can be hard to understand for normal users.

“实现图形”是什么意思?通常,项目在选中时会以SystemColors.HighlightBrush的背景呈现。对于普通用户来说,除此之外的任何系统都很难理解。