I'm binding an UI to an interface (which is implemented by several presenters, not accessible from the UI assembly).
I really like d:DesignInstance in designer because it (kind of) makes xaml strongly typed using R#.
Sadly, d:DesignInstance does not support interface types: "Cannot create an instance of an interface."
The first thing I thought is: Ok, no problem, let's create a custom markup extension which takes a System.Type as parameter, and which ProvideValue method returns a fake instance of it (dummy implementation of this interface, generated by dynamic IL emission).
This works quite well, bindings are resolved at design-time (I can see that in the design panel since my markup extension fills the object properties with a lorem-ipsum)
BUT the nicest R# feature dont work: Resharper does not recognize datacontext type, and just gives a message "Cannot resolve property '{0}' in data context of type 'object'"
Does someone know how to fix this ?
(any alternative which would allow me to let R# know about an interface datacontext type would be great)
Thanks !
ps: I also tried to create another markup extension which returns the generated runtime type in order to give it to DesignInstance: "{d:DesignInstance Type={utilsUi:InstanceType commons:User}}" => Gives the error "Object of type 'InstanceType' cannot be converted to type 'System.Type'"
... seems that DesignInstance does not support inner markup extensions :(
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…