【发布时间】:2012-02-17 10:54:31
【问题描述】:
我是 WPF 和 MVVM 的新手。我的 WPF 应用程序的 mainWindowView 中有 Frame。我已将框架的源绑定到视图模型的 SourcePage 属性:
<Frame Name="frame" Content="Frame" Source="{Binding Path=SourcePage, Source={StaticResource WindowViewModel}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
在视图模型中,
public string SourcePage
{
get
{
return _sourcePage;
}
set
{
if (value != null)
{
_sourcePage = value;
OnPropertyChanged("SourcePage");
}
}
}
最初,我通过在 viewmodel 构造函数中设置 sourcepage 值在该框架中加载了 selectTest 视图:
public MainWindowViewModel()
{
SourcePage ="Std.User/SelectTest.xaml";
}
现在点击按钮,我需要执行一些数据库操作,然后我想在该框架中加载另一个视图。
您好 Colin,感谢您的即时回复。但我也尝试过,但它没有按预期工作。这是我的代码
public ICommand StartTestCommand
{
get
{
if (_startTest == null)
{
_startTest = new DelegateCommand(StartTest);
}
return _startTest;
}
}
private void StartTest()
{
MainWindowViewModel mwvm = new MainWindowViewModel();
mwvm.SourcePage = "std.user/ChangePassword2.xaml";
}
【问题讨论】:
标签: wpf mvvm navigation frame