使用 RelayCommand进行导航在 MVVM 轻量级中
我一直在关注 Jesse Liberty 的 tutorial on MVVM Light for Windows Phone 7,但我陷入了这个问题。我需要从主页导航到详细信息页面。按照本教程,我在 MainViewModel 中使用 RelayCommand:
public RelayCommand<Customer> DetailsPageCommand { get; private set;}
然后在构造函数中初始化它:
DetailsPageCommand = new RelayCommand<Customer>((msg) => GoToDetailsPage(msg));
最后实现 GoToDetailsPage 方法:
private object GoToDetailsPage(Customer msg)
{
System.Windows.MessageBox.Show("Go to details page with: " +
msg.First +
" " +
msg.Last );
return null;
}
显示消息框有效,但我不确定如何导航到详细信息页面。在教程的前面部分中,页面导航是通过如下方式处理的:
var msg = new GoToPageMessage {PageName = "DetailPage"};
Messenger.Default.Send(msg);
I have been following Jesse Liberty's tutorial on MVVM Light for Windows Phone 7, but I'm stuck on this problem. I need to navigate from a main page to a detail page. Following the tutorial, I'm using a RelayCommand in the MainViewModel:
public RelayCommand<Customer> DetailsPageCommand { get; private set;}
I then initialize it in the constructor:
DetailsPageCommand = new RelayCommand<Customer>((msg) => GoToDetailsPage(msg));
Finally you implement the GoToDetailsPage method:
private object GoToDetailsPage(Customer msg)
{
System.Windows.MessageBox.Show("Go to details page with: " +
msg.First +
" " +
msg.Last );
return null;
}
Showing the message box works, but I'm not sure how to navigate to the detail page instead. In previous sections of the tutorial page navigation was handled with something like this:
var msg = new GoToPageMessage {PageName = "DetailPage"};
Messenger.Default.Send(msg);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要注册才能接收该类型的消息,然后进行适当的导航。
以下假定页面名称,并且您通过在查询字符串中传递特定客户的 ID 来导航到特定客户的详细信息。
然后,您可以相应地调整您的代码:
我希望这会有所帮助。
You'll need to register to receive messages of that type and then navigate appropriately.
The following assumes a page name and that you're navigating to details of the specific customer by passing their Id in the query string.
You'd then adjust your code accordingly:
I hope this helps.