I would like to create sample data which are created only in design mode (When the WPF Window is shown in the Visual Studio WPF Designer or in Expression Blend). I tried this:
public MainWindow()
{
InitializeComponent();
if (DesignerProperties.GetIsInDesignMode(this))
{
DataContext = new Person() { Name = "Harry" };
}
}
It seems that the designer doesn't call the constructor of the Window class. I need to create the sample data in C# code because they are more complicated to instantiate. Any ideas?
Now I’m using the design-time support of Visual Studio 2010 and Expression Blend 4. This new feature meets most of my requirements.
How this works is shown in the BookLibrary sample application of the WPF Application Framework (WAF). Please download the .Net4 version of WAF.