Hey Karl,
I have been playing with d:DataContext for a prototype I am building for a customer.
Here is the situation: I have some Views which are transient (in fact they are created by MEF, but that’s not relevant here). I set the DataContext on these temporary views programmatically.
One view represent an Account, returned by a service, with a contract of IAccount. In order to enable design, I thought I would create a DesignAccount : IAccount. In this class, I created some properties returning some design time value.
When I test, I see that the DesignAccount constructor gets called, so the d:DataContext works (in VS10 and in Blend 4). However the properties are never called. For example, my IAccount defines a FriendlyName of type string. In DesignAccount, FriendlyNamesimply returns “Hello”.
I try to bind a TextBlock.Text to {Binding FriendlyName}. My expectation was to see “Hello” on the design surface, allowing me to style it. However, nothing appears. In fact the property doesn’t even get called.
Re-reading your article at http://karlshifflett.wordpress.com/2009/10/28/ddesigninstance-ddesigndata-in-visual-studio-2010-beta2/, I get the feeling that the DesignAccount is really just a shape for the DataBinding editor, and that its properties are ignored. Am I right? If I am right, it is too bad, because we would have had the possibility to use these “faux types” for real design work. Instead I can only use that for the Data binding editor.
What am missing my friend?
Cheers,
Laurent
--
Laurent Bugnion [Microsoft MVP, MCP]
Blog: http://blog.galasoft.ch
Support children in Calcutta: http://www.calcutta-espoir.ch
|
|
as |
Laurent,
Go back and re-read the section, Creating Creatable Types.
If you use this syntax the real type will be used.
<Grid d:DataContext="{d:DesignInstance local:Person, IsDesignTimeCreatable=True}">
If you still have a problem, send me a small example project.
Cheers,
Karl