开发者

Accessing data from an Adorner

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 s开发者_开发知识库hapes in my class


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜