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";
}