【发布时间】:2017-09-03 18:54:39
【问题描述】:
我有一个框架控件,它的源设置为 xaml 中的页面,如下所示:
Source="/Myapp;component/MyFolder/Mypage.xaml"
框架控件在我运行应用程序时显示页面。但我想在设计时看到在框架控件上显示的页面。(Visual Studio 2017)。它只显示这样的文本:(/Myapp;component/MyFolder/Mypage.xaml)
【问题讨论】:
我有一个框架控件,它的源设置为 xaml 中的页面,如下所示:
Source="/Myapp;component/MyFolder/Mypage.xaml"
框架控件在我运行应用程序时显示页面。但我想在设计时看到在框架控件上显示的页面。(Visual Studio 2017)。它只显示这样的文本:(/Myapp;component/MyFolder/Mypage.xaml)
【问题讨论】:
这适用于设计时的单个页面。
确保在根 xaml 元素中定义了 Blend 命名空间。
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
然后将d:DesignInstace 属性添加到您的Frame。
<Frame d:DataContext="{d:DesignInstance Type=local:MyPage, IsDesignTimeCreatable=True}"
Content="{Binding}"/>
然后在InitializeComponent 调用之后,将类似的内容添加到托管Frame 的构造函数中。
public MainWindow()
{
InitializeComponent();
_frame.Content = null;
_frame.NavigationUIVisibility = NavigationUIVisibility.Visible;
_frame.Source = new Uri("/Wpf;component/MyPage.xaml", UriKind.Relative);
}
这应该允许您正常使用Source 属性进行导航。
【讨论】:
Source 属性是最好的方法,因此我编辑了答案以删除该部分。你是如何浏览框架页面的?