1

I don't know if this is the best way, but what I am trying to do is to create a collection of Shape objects and then bind it to a Canvas, then whenever I update these Shapes, or add new Shapes (rare), the Shape objects on the Canvas will update as well.

Btw the Shape objects are not all the same, some Lines, Rectangles, etc. Not sure if that matters.

What's the best way to do this?

Joan Venge
  • 315,713
  • 212
  • 479
  • 689
  • 2
    Possible duplicate of: http://stackoverflow.com/questions/889825/wpf-is-it-possible-to-bind-a-canvass-children-property-in-xaml – ChrisWue Apr 08 '11 at 19:57
  • Thanks I saw that one but it seems like it only handles shapes of one type? Also he didn't provide the source for the converter. – Joan Venge Apr 08 '11 at 20:13

1 Answers1

2

If you look at the question Is it possible to bind a Canvas's Children property in XAML? and further down there is an answer from Ivan which uses an attached property you can bind to and it automatically updates the canvas children. I haven't tried it but looks like it should work. Seems the best solution to me. The other option is to use the ItemsControl with a DataTemplate for each type you want to show - however that seems a bit fiddly.

Community
  • 1
  • 1
ChrisWue
  • 18,612
  • 4
  • 58
  • 83