I am new to WPF and MVVM. I have a Frame in mainWindowView in my WPF application. I bind the frame source to the SourcePage property of the view model:
<Frame Name="frame" Content="Frame" Source="{Binding Path=SourcePage, Source={StaticResource WindowViewModel}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
In view model
public string SourcePage { get { return _sourcePage; } set { if (value != null) { _sourcePage = value; OnPropertyChanged("SourcePage"); } } }
I originally loaded selectTest view into this frame by setting the value of the original page in the viewmodel constructor:
public MainWindowViewModel() { SourcePage ="Std.User/SelectTest.xaml"; }
Now, by clicking the button, I need to perform some operations with the database, after which I want to load another view in this frame.
Hi Colin, thanks for the quick reply cheers. But I tried the same, and it does not work as expected. Here is my code
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"; }
source share