As far as I know a possible implementation for this particular scenario using the
MVVM approach could be for example to define an ObservableCollection
of FrameworkElements in your ViewModel. This
ViewModel could consume a service that contains the logic to retrieve / create each
FrameworkElement with its corresponding data.
Then you could bind your ViewModel's ObservableCollection property to the
ItemsSource property of your container control which you will use to display the elements in the view.
The problem you may find is that Canvas is a "primitive container" and does not have an
ItemsSource property to bind to. The Panel.Children
property is read only, and it wont allow you to directly bind it to the ViewModel's
ObservableCollection. Hence, as far as I know this cannot be directly achieved.
As a workaround for this, for example you could customize an ItemsControl
to look like a Canvas by changing the ItemsPanel
property to Canvas.
You could find more information about this in the following thread:
Also, I believe you could find the following threads interesting, as I believe they could be related to your scenario:
Also, as this particular implementation is not strictly related to Prism, I believe you could find more information on how to achieve it for example in the
I hope you find this handy,