WPF 在 IDE 中设计时显示框架的内容(WPF 页面)(Visual Studio 2017)



我有一个框架控件,它的源代码设置为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 属性进行导航。

最新更新