wpf - 通过XAML将Window.Content设置为页面吗?

标签 wpf xaml window

<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>

我想将窗口的内容设置为页面,就像我将以编程方式进行操作一样:
Dim w As New MyWindow
Dim p As New MyPage
w.Content = p
w.ShowDialog()

或在窗口的Load事件中设置它,总的来说,我希望它在xaml中完成。

最佳答案

使用Frame元素显示页面内容。

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

关于wpf - 通过XAML将Window.Content设置为页面吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1371056/

相关文章:

wpf - 使用 MVVM 将焦点设置到 WPF 中的控件

wpf - 将Dockpanel内容置于顶部的网格内

wpf - 如何在 WPF 中禁用上下文菜单?

c# - 在 C# View 模型中访问 XAML 对象

c# - 让 XAML 设计器在 VS2010 中显示设计

user-interface - pharo smalltalk,阻止对话和 parent 窗口

c# - 如何更直观地设计 WPF 事物,a-la WinForms?

silverlight - 使用 VisualStateManager 按下时更改按钮的背景图像

javascript - 当我的javascript打开的窗口关闭时如何捕获事件

c# - 将 Ctrl+C 发送到上一个事件窗口