Reputation: 11
I'm wondering if someone could give me some guidance on a Silverlight problem I'm having?
What I am doing now is building a page in Silverlight using the MVVM pattern to retrieve and display my data. My page will be a standard "List" type page that uses the datagrid to display and filter data.
What I would like to do is, If the user clicks an edit button on this list page, I would like to navigate to a details page which will contain a dataform that I want to bind to the same collection of data that is bound to the datagrid of the list page. What I'm thinking has to happen is the List ViewModel has to create the Details Page and set the Details Page datacontext to itself (being the instance of the List ViewModel). I'm not sure how I would create the view, navigate to it and pass the reference to the view model.
You may be wondering why i would want a details page that takes a collection. This is so I can simulate behaviour that my user is familiar with in their current access application. Mostly, it comes in handy when the user filters the list view they are able to enter a page where they could navigate and edit any of the results from their filter without having to open and close the details page repeatedly.
Upvotes: 0
Views: 354
Reputation: 1174
MVVM is well suited to this. You are right in assuming they both share the same view model, as the data is the same and you can automatically update the data in both locations at once.
However, I would avoid getting the view model to create the views. This is often seen as the wrong way to implement MVVM as it creates a coupling from the view models to the views which may get you into trouble later.
A solution with sample code is described in this blog post.
Upvotes: 1