Back to list
Views:   10.6K
Replies:  1
Archived

Navigate to View from ViewModel and pass data.

Good Evening,

Im 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.

If you have any advise or an alternate pattern to achieve this kind of functionality it would be greatly appreciated.

Regards,
Chris Nickel, Apr 07, 2011
Reply 1
There are probably numerous was to accomplish this, what I usually do (in WPF, I haven't done any SL development) is the following:

1. Click edit button on list page, fires an edit command in ListVM
2. ListVM Edit Command gathers necessary data and creates an EditList event (and adding the data to the event)
3. Trigger the event using Event Aggregator Design Pattern
4. ListView (or someone else) listens to the EditList event, and display a EditView page
5. Populate the EditViewModel with data fetched from the EditList event

Not sure this is best solution, but I found it useful. The Event Aggregator pattern is beneficial when communication between loosly coupled Views and their ViewModels.


Good Luck!

Robert Blixt, Apr 08, 2011


Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas.      Vsn 1.2.2