Reputation: 331450
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?
Upvotes: 1
Views: 1515
Reputation: 19060
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.
Upvotes: 2