0

I have a requirement to display a number of graph/chart "thumbnails". Clicking one will show an "expanded view" (in a separate panel) that displays a larger version of the chart, plus controls to view and manipulate the chart.

There will be a number of different charts, each plotting my data in different ways. Also, a given chart type may appear several times, each plotting a different subset of the data. The controls in the "expanded" view will also differ from one chart type to the next, so there is little commonality here.

I'm struggling to get my head around how to model all this in MVVM, especially given the need to dynamically create an unknown number of thumbnails (and in some cases multiple instances of the same type).

Thinking aloud, I guess I need a view/viewmodel that represents a single thumbnail (the view contains the chart component and the VM exposes the data to plot). I guess I also need a V/VM for the "thumbnail list" UI, responsible for creating the thumbnails and exposing them via a collection for binding to the list. But how does it instantiate these? A VM gets injected into its view, suggesting the "thumbnail list" VM would have to dynamically instantiate the thumbnail views - but a VM shouldn't have knowledge of views should it?!

Lastly, when I display the "expanded" view, it would make sense to (somehow) pass it the charting component/view that was used in the thumbnail, to avoid having to render the chart again, but how?

If it's relevant/helps, I'm using Castle Windsor for dependency injection, and the navigation features of Prism.

1 Answer 1

1

This is indeed a complex topic,...

I would suggest a VM for the list of icons not necessarily for the icon itself. this can be bound to properities of the IconListViewModels. Then you should think about a ChartViewModelFactory. Which works in conjunction with your DIC.

An important discussion is the VM-V marriage. View first or View Model first... one way could also be ViewResolver if which returns the matching view based on your view model... this can rely on some sort of conventions. So the final steps could be ask the factory for a view model find the matching view glue them together and bind them to a content presenter...

I hope this helps to get you started...

Sign up to request clarification or add additional context in comments.

2 Comments

Regarding the single IconListViewModels VM - not sure I could expose each thumb's data as a separate property as the number of "data sets" will vary at runtime. I could use an array, but how could I configure each thumb view to bind to a different element of that property? I'm instead thinking of passing the data set to the ViewResolver, which would then assign it to the view's DataContext. You've pointed me in the right direction and given me a few things to think about. And I hadn't thought of binding a view to a ContentPresenter either - good tip!
It depends like always ... my point was to keep the nested VM low. An think about if it has to be a complex ViewModel or just some properties...but I a havn't see any code so no judges here. But suggestion could be: the IconListViewModel should contain an OberservableCollection<ThumbData> ... could also be ObservableCollection<ThumbData>. Glad I could help. Please mark the q. as answerd if it helped =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.