View navigation in
In the WPF MVVM application, the view navigation involves setting the DataContext of ContentControl to be set to the corresponding ViewModel. By binding ContentControl to the ViewModel attribute of the parent ViewModel, you can easily switch the view in the ViewModel.
Define a base class for your ViewModel, such as BaseViewModel, which contains public attributes and interfaces, such as InotifyPropertyChanged. This base will provide a public structure for all ViewModels.
Create data binding in the app.xaml In the App.xaml file, it is specified to connect the viewmplate to the corresponding ViewModel. For example:
Set ViewModel in MainViewModel
In the mainViewModel, create a ViewModel attribute that can be set to different viewmodels:Public BaseViewModel ViewModel {get; set;}
In your mainwindow.xaml, use ContentControl to display the current viewmodel:
public BaseViewModel ViewModel { get; set; }
Define commands in MainViewModel In the mainViewModel, define a command. The command sets the ViewModel property to the required ViewModel:
Public Icommand DisplayersonView => New ActionCommand (
() => ViewModel = New PersonviewModel (),
() =>! IsViewModeloftype
You can seamlessly navigate the view view in WPF MVVM applications. This method provides a flexible and easy -to -maintain way to realize any part of the application view conversion.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3