问题
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