4
我是WPF和MVVM的新手。我在我的WPF应用程序中的mainWindowView中有Frame。我已经帧的源结合视图模型的SourcePage属性:通过WPF视图模型更改源代码导航框架
<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");
}
}
}
最初我已经通过在视图模型的构造设定sourcepage值加载selectTest视图在该帧中:
public MainWindowViewModel()
{
SourcePage ="Std.User/SelectTest.xaml";
}
现在单击按钮,我需要执行一些数据库操作,之后我想在该框架中加载另一个视图。
嗨科林,感谢您的立即回复。但我已经尝试过,并没有像预期的那样工作。这里是我的代码
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";
}