【问题标题】:Wpf Show Frame's Content(Wpf Page) at Design Time In IDE(Visual Studio 2017)Wpf 在 IDE 中的设计时显示框架的内容(Wpf 页面)(Visual Studio 2017)
【发布时间】:2017-09-03 18:54:39
【问题描述】:

我有一个框架控件,它的源设置为 xaml 中的页面,如下所示:

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

框架控件在我运行应用程序时显示页面。但我想在设计时看到在框架控件上显示的页面。(Visual Studio 2017)。它只显示这样的文本:(/Myapp;component/MyFolder/Mypage.xaml)

【问题讨论】:

    标签: wpf frame


    【解决方案1】:

    这适用于设计时的单个页面。

    确保在根 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 属性进行导航。

    【讨论】:

    • 我刚刚尝试过,现在我可以在设计时看到该页面,但我无法在运行时使用 frame.source 导航该页面。
    • 不确定使用 Source 属性是最好的方法,因此我编辑了答案以删除该部分。你是如何浏览框架页面的?
    • 通常我使用源属性来导航页面。但是在使用您的 xaml 代码后,我无法再使用源属性导航了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 1970-01-01
    • 1970-01-01
    • 2014-06-04
    • 1970-01-01
    相关资源
    最近更新 更多