I have a WPF project, I add a frame in the Windows,the source of the frame is the page. I want to achieve clicking a button in the page to change the page of the frame.
EDIT: A functional solution can look like:
MainWindow XAML:
<StackPanel>
<Frame Name="frmMainContent" Height="260"
DataContext="MyPageInformation"
Source="{Binding}"
NavigationUIVisibility="Hidden">
</Frame>
</StackPanel>
MainWindow cs:
frmMainContent.Source = new Uri("test1.xaml", UriKind.Relative); // initialize frame with the "test1" view
test1 XAML:
<Grid>
<Button Click="ButtonBase_OnClick" Background="Red" Height="30" Width="100">Go to page 2</Button>
</Grid>
test1 cs:
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
NavigationService ns = NavigationService.GetNavigationService(this);
ns.Navigate(new Uri("test2.xaml", UriKind.Relative));
}
test2 XAML:
<Grid>
<Button Click="ButtonBase_OnClick" Width="100" Height="30" Background="RoyalBlue"> Go to page 1</Button>
</Grid>
test2 cs:
NavigationService ns = NavigationService.GetNavigationService(this);
ns.Navigate(new Uri("test1.xaml", UriKind.Relative));
This is a working solution using NavigationService.