Reputation: 5087
I am trying to use a frame
to host different type of xaml pages. The user will select the page to be loaded.
I want to load a page with a non-default constructor into the Frame.
I found the following code on MSDN:
void hyperlink_Click(object sender, RoutedEventArgs e)
{
// Instantiate the page to navigate to
PageWithNonDefaultConstructor page = new PageWithNonDefaultConstructor("Hello!");
// Navigate to the page, using the NavigationService
this.NavigationService.Navigate(page);
}
The above code replaces the currently displayed page, but I want it to load into a specific frame element on the current page.
<Frame Source="Default.xaml" />
How can this be done?
Upvotes: 1
Views: 1422
Reputation: 4324
You can solve the problem using the Content of Frame instead of Source.
//xaml
<Page x:Class="WpfApplication1.Something"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow">
<StackPanel>
<Button Click="Button_Click" Content="click"/>
<Frame Content="{Binding}"/>
</StackPanel>
</Page>
//codebehinde
private void Button_Click(object sender, RoutedEventArgs e)
{
// Instantiate the page to navigate to
Page1 page = new Page1("Hello!");
this.DataContext = page;
}
Upvotes: 2