Wpf Show Frame's Content(Wpf Page) at Design Time In IDE(Visual Studio 2017)

北慕城南 提交于 2019-12-11 06:19:31

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/43294210/wpf-show-frames-contentwpf-page-at-design-time-in-idevisual-studio-2017

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!