简体   繁体   English

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

[英]What is the best way to implement the graphics for a selected item in a WPF user control?

I have implemented a few different WPF user controls. 我实现了一些不同的WPF用户控件。 In doing so I have also implemented a few different ways of implementing the graphics for when an item is selected. 这样做时,我还实现了几种不同的方式来实现选择项目时的图形。

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中指示选择的元素。

What do you mean by "implementing the graphics"? “实现图形”是什么意思? Usually an item is rendered with a background of SystemColors.HighlightBrush when it's selected. 通常,选择一个项目时,其背景为SystemColors.HighlightBrush Any system other than that can be hard to understand for normal users. 普通用户很难理解除此以外的任何系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM