Wpf在IDE(Visual Studio 2017)中设计时显示框架内容(Wpf页面)。[英] Wpf Show Frame's Content(Wpf Page) at Design Time In IDE(Visual Studio 2017)

本文是小编为大家收集整理的关于Wpf在IDE(Visual Studio 2017)中设计时显示框架内容(Wpf页面)。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有一个帧控件,它的源设置为XAML中的页面:

Source="/Myapp;component/MyFolder/Mypage.xaml"

帧控件在我运行应用程序时显示页面.但是我想查看在设计时在框架控件处显示页面.(Visual Studio 2017).它仅显示这样的文字:(/米普; component/myfolder/mypage.xaml)

推荐答案

这将在设计时间内适用于单个页面.

确保您在根XAML元素中定义了混合名称空间.

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

然后将d:DesignInstace属性添加到您的Frame.

<Frame d:DataContext="{d:DesignInstance Type=local:MyPage, IsDesignTimeCreatable=True}"  
       Content="{Binding}"/>

然后将类似的东西添加到您的Frame InitializeComponent调用后托管的构造函数.

之后.

public MainWindow()
{
    InitializeComponent();
    _frame.Content = null;
    _frame.NavigationUIVisibility = NavigationUIVisibility.Visible;
    _frame.Source = new Uri("/Wpf;component/MyPage.xaml", UriKind.Relative);
}

应该允许您正常使用Source属性导航.

本文地址:https://www.itbaoku.cn/post/2091173.html

问题描述

I have a frame control and it's source set to a page in xaml like this:

Source="/Myapp;component/MyFolder/Mypage.xaml"

Frame control shows the page when i run the application. But i want to see page displaying at frame control at design time.(Visual Studio 2017). It only shows a text like this: (/Myapp;component/MyFolder/Mypage.xaml)

推荐答案

This will work for a single page in design time.

Make sure you have the Blend namespace defined in your root xaml element.

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

Then add the d:DesignInstace attribute to your Frame.

<Frame d:DataContext="{d:DesignInstance Type=local:MyPage, IsDesignTimeCreatable=True}"  
       Content="{Binding}"/>

Then add something like this to your to the constructor where your Frame is hosted, after the InitializeComponent call.

public MainWindow()
{
    InitializeComponent();
    _frame.Content = null;
    _frame.NavigationUIVisibility = NavigationUIVisibility.Visible;
    _frame.Source = new Uri("/Wpf;component/MyPage.xaml", UriKind.Relative);
}

That should allow you to navigate with the Source property normally.