Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Summary of WPF designer limitations and rules for WYSIWYG view creation?

For WPF/Silverlight/XAML4Win8/WP8/whathaveyou, the visuals are created by (I believe) newing up an instance of the base class that your custom view (window/page/usercontrol/whathaveyou) is derived from, and then applying your XAML after the fact.

If I'm not mistaken this means codebehind in the type's constructor is lost. Is there a way to execute design-time object creation logic in the view itself? More importantly is there a good summary online somewhere of how the Cider/Blend designers actually create the WYSIWYG views at design time? I seem to recall some documentation on this somewhere (Expression Studio docs maybe?) But I can't find them for the life of me.

like image 526
Firoso Avatar asked Nov 11 '22 15:11

Firoso


1 Answers

http://msdn.microsoft.com/en-us/library/ff602274(v=vs.95).aspx

The above link applies to Silverlight, but pretty sure most if not all applies to WPF as well.

You can instantiate a designer DataContext.

    <Grid x:Name="LayoutRoot" Background="White" 
          d:DataContext="{d:DesignInstance Type=local:Customer}">

One limitation is that it requires you to have a default constructor. Here is an answer I found to get around it. How to use d:DesignInstance with types that don't have default constructor?.

Best would be to subclass the data you are coding against and have it do any necessary initializing. Luckily everything you are defining is purely for the designing and has no effect on what objects you are actually working with at runtime.

Unfortunately I do not have answers for the rest of the questions.

like image 91
TyCobb Avatar answered Nov 14 '22 22:11

TyCobb