从装饰器访问数据
我正在用 C# 和 WPF 编写一个 2D 图形工具,并且在绘制到 Canvas
的 Shapes
上使用 Adorners
。
我希望装饰器在形状被视为“选定”时突出显示,我目前正在使用 MouseDown
和 MouseUp
事件执行此操作。
但是,用户可以选择多个形状,因此并非所有形状都会接收这两个鼠标事件。
我有一个管理绘图的类,其中包含所选形状的List
。让装饰者访问此数据的最佳方式是什么,以便他们可以查看他们的装饰元素是否被选择?
我考虑过一些事情:
- 使
List
全局 - 坏主意 - 对每个形状进行子类化以添加“选定”属性 - 需要更改对我的类中形状的所有引用
I'm writing a 2D graphics tool in C# and WPF, and I'm using Adorners
on the Shapes
drawn to Canvas
.
I'd like the adorners to highlight when a shape is considered "selected", which I'm currently doing using MouseDown
and MouseUp
events.
However, the user can select multiple shapes, so not all of the shapes will receive both of the mouse events.
I have a class that manages the drawing, which holds a List
of the selected shapes. What is the best way to give the adorners access to this data, so they can see if their adorned element is selected?
Some thing's I've considered:
- Making the
List
global - bad idea - Sub-classing each shape to add a "selected" property - would require changing all references to the shapes in my class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建在形状上设置的附加依赖属性 - 然后您可以在选择一个属性时设置该属性。
装饰器可以将可见性绑定到形状上的属性,以便您自动设置可见性。
您还可以使用形状上的 Tag 属性来存储值 - 这是旧的方法:)
You can make an attached dependencyproperty you set on your shape - then you can set that property when you select one.
The adorner can have a visibility binding to the property on the shape so you get visibility set automatic.
You can also use the Tag property on the shape to store values - that is the old way of doing it :)