Install Window.Content on a page using XAML?

<Window x:Class="MyWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:src="clr-namespace:WpfApplication1"
    Title="ContactsSelector" Height="300" Width="300">
    <Window.Content>
        <src:MyPage>
           <!--MyPage is a page that I created and exists in the project--> 
        </src:MyPage>
    </Window.Content>
</Window>

I want to set the contents of a window to a page, as if I did it programmatically:

Dim w As New MyWindow
Dim p As New MyPage
w.Content = p
w.ShowDialog()

Or set it in the Load event in the window, in short, I want this done in xaml.

+5
source share
2 answers

Use the Frame element to display the contents of the page.

<Window> <Frame Source="/Pages/MyPage.xaml"/> </Window>
+9
source

Try something like this, where MyPageAssembly points to the assembly your page is on, and MyPage is the name of the page.

<Window 
    x:Class="MyWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:MyPageAssembly="clr-namespace:MyPage;assembly=MyPageAssembly"
    Title="ContactsSelector" 
    Height="300" 
    Width="300"
    >
    <Window.Content>
        <MyPageAssembly:MyPage />
    </Window.Content>
</Window>
+3
source

All Articles