Search code examples
c#wpfbuttonuser-controls

c# WPF button link to user control page


I have a MainWindow which only have a button , How do i link this button to a user control page ( home.xaml) ? i am new to WPF in my mainwindow :

<Button Height="100" Name="btnHome" Width="103" Click="btnHome_Click"/>

in my mainwindow.cs:

    private void btnHome_Click(object sender, RoutedEventArgs e)
    {
        var home = new home();
        home.Show();
    }

but it doesnt work . home.xaml is my user control page that i want to link to by clicking on the button in mainwindow.


Solution

  • You should be able to use the NavigationService to navigate between WPF Pages

    Example:

    private void btnHome_Click(object sender, RoutedEventArgs e)
    {
        NavigationService.GetNavigationService(this).Navigate("home.xaml");
    }