加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 02:52:39 所属栏目:Windows 来源:网络整理
导读: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 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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读