Ok, the thing is that the Page
control can only be shown in a Frame
or a NavigationWindow
when using a WPF application, so what you need to do is:
In the Window XAML you need to add a Frame
control as shown bellow:
<Window x:Class="WpfTestPageQuestion.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Content="Load Page" Click="show_page_Click"/>
<Frame Grid.Row="1" x:Name="frame"/>
</Grid>
</Window>
Then you need to add the handler for the Click Event for the button click:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void show_page_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("This should open the -page- window");
var mypage = new Page();
mypage.Background = Brushes.Red;
mypage.Content = new TextBlock
{
Text = "Hello from the Page!",
FontSize = 30,
VerticalAlignment = System.Windows.VerticalAlignment.Center,
HorizontalAlignment = System.Windows.HorizontalAlignment.Center
};
frame.Content = mypage;
MessageBox.Show("Page shown =D");
}
}
And you are done. A Page content addent to the Window.
Hope this helps.
All Best
Raul Mainardi Neto