MVVM 的新手。我没有使用任何 MVVM 框架(WAF/MVVM Light)。我使用 Josh Smith 的 relayCommand 类。
有两种形式,Win_Login(btnCancel 和 btnNext),另一种是带有组合框和两个按钮(btnBack,btnNext)的选择表 - 用户可以在其中选择 GOOG、MSFT 等股票行情。
我写了一个基本的 View 骨架 ,以及用于登录和选择表单的ViewModel 。
我想要实现的是成功登录,关闭登录视图并打开选择表单,然后单击(btnBack)应该再次显示 loginForm。Windows 是Singleton。
我将视图的 dataContext 设置为
<Window
x:Class="Ticker.Win_Login"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Ticker"
Title="Ticker-Login" Height="312" Width="394" WindowStartupLocation="CenterScreen" Background="#F9FBF4" >
<Window.DataContext>
<local:Win_LoginViewModel/>
</Window.DataContext>
<Grid></Grid
在 Win_LoginViewModel
private void LoginExecute()
{
if (!CanLoginExecute()) return;
try
{
//how I'll call close the current view
//how I'll call selectTicker view
}
catch (Exception)
{
throw;
}
}
在 Win_SelectTickerViewModel
private Boolean CanBackExecute()
{
return true;
}
private void BackExecute()
{
if (!CanCancelExecute())
{
return;
}
//how I'll implement back here.
}
如果有人可以为给定场景提供一些简单的解决方案(pbbly 带有一些示例代码),我将非常感激。