开发者

Setting the ViewModel of a View when using Navigation Service in Silverlight

I'm am having trouble finding out how I would create an instance of a view model and set that as the view model of a view am I am going to navigate to using the Silverlight navigation framework.

for instance, If I have a list view with a view model, I would like the list view to use the navigation service to navigate to the details view and and set the view model of the details view to the same instance of the view model that the list view is using.

From what I have read and understand, there is no way to pass data along when using the Navigate method. And the navigate method does not return the instance of the view that will be navigated to?

So my question is... Once I have used .Navigate(URI) to navigate my silverlight application to the detail view, how ca开发者_JAVA技巧n I set the viewmodel of detail view to the instance in list view before i navigate away from the list view.


First of all, your statement "From what I have read and understand, there is no way to pass data along when using the Navigate method" is incorrect. You can pass simple data values via parameters.

You can also share a datacontext between views by using a navigation frame. Check this SL3 article out:

http://timheuer.com/blog/archive/2009/04/03/share-data-between-navigation-pages-in-silverlight-3.aspx


You can use the query string to pass parameters to the view you want to navigate to, then use those parameters to create the ViewModel.

here is a post about "Site Navigation Basics in Silverlight 4" that shows how to use query string parameters in Silverlight navigation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜