You can use the VisualTreeHelper class to find the Frame
that contains the Page
and, set the Source
property of the Frame
to the new Page
.
You can implement the Click
event-handler of your Button
, as the following:
private void btnChangePage_Click(object sender, RoutedEventArgs e)
{
Frame pageFrame = null;
DependencyObject currParent = VisualTreeHelper.GetParent(this);
while (currParent != null && pageFrame == null)
{
pageFrame = currParent as Frame;
currParent = VisualTreeHelper.GetParent(currParent);
}
if (pageFrame != null)
{
pageFrame.Source = new Uri("Page2.xaml", UriKind.Relative);
}
}