从装饰器访问数据

发布于 2024-10-02 12:30:56 字数 447 浏览 0 评论 0原文

我正在用 C# 和 WPF 编写一个 2D 图形工具,并且在绘制到 CanvasShapes 上使用 Adorners

我希望装饰器在形状被视为“选定”时突出显示,我目前正在使用 MouseDownMouseUp 事件执行此操作。

但是,用户可以选择多个形状,因此并非所有形状都会接收这两个鼠标事件。

我有一个管理绘图的类,其中包含所选形状的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月打碎记忆 2024-10-09 12:30:56

您可以创建在形状上设置的附加依赖属性 - 然后您可以在选择一个属性时设置该属性。
装饰器可以将可见性绑定到形状上的属性,以便您自动设置可见性。

您还可以使用形状上的 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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文