Page - GetcuReone/MvvmFrame.Wpf GitHub Wiki

Page

This is one of the main parts that contains a set of methods for working with a view. With its help, the library can bind view and view-model

How to use it?

Let's find out by example.

  1. Create an empty WPF application. I will call him Example_MvvmFrame.Wpf
  2. Download the NuGet 'MvvmFrame.Wpf' to the project.
  3. For ease of understanding, create a subfolder 'Pages'
  4. In this folder we create the page 'HomePage' and open its code behind. Before you should be the following picture
namespace Example_MvvmFrame.Wpf.Pages
{
    /// <summary>
    /// Interaction logic for HomePage.xaml
    /// </summary>
    public partial class HomePage : Page
    {
        public HomePage()
        {
            InitializeComponent();
        }
    }
}
  1. Remove the default constructor. Inherit the class 'HomePage' from the interface 'MvvmFrame.Interfaces.IPage' and implement the interface method like this:
namespace Example_MvvmFrame.Wpf.Pages
{
    /// <summary>
    /// Interaction logic for HomePage.xaml
    /// </summary>
    public partial class HomePage : Page, IPage
    {
        public void InitializePageComponent<TViewModel>(TViewModel viewModel) where TViewModel : IViewModel
        {
            DataContext = viewModel;
            InitializeComponent();
        }
    }
}

That's all. Your page is ready to go :) Further work on view-model

This example is useful for further study of the library.

⚠️ **GitHub.com Fallback** ⚠️