开发者

wpf page navigation in view model

in my view I have a button. The button has a Relay Command, which do some action. After this action it should navigate to an other site. How can I do this. How can I navigate to this site inside my viewModel? I hope you understand what I mean.

Thanks for your help 开发者_运维技巧holzleube


Unfortunately, the answer to that question may not be as straightforward as you'd like. I think everybody has a slightly different way of doing it, so this is just one way. First off, we use the Prism/CAL library from Microsoft, which has this notion of "regions", which are named placeholder controls (i.e. ItemsControl, sort of). Then on all of our "pages", we take in an instance of a controller we make called a NavigationController, whose duty it is to swap out views. The NavigationController is full of methods like "GoToHome" which do things like: grab the Home ViewModel from dependency injection (or make a new instance, depending on your setup), clear out a certain region by obtaining it from the region manager, then load it with the new Home view model. Then we wire up the call in our "page"'s backing view model to call the controller.

So, in summary, it takes some plumbing. Once you've got the initial setup, it only takes a few minutes to add a new page, but there is no magical "link" because you have to know where you're going, where it loads, and how to obtain the backing viewmodel.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜