Thursday, November 3, 2022

Using design datacontext to provide intellisense while binding

I stumbled across a nice feature in Visual Studio that may be useful to you. You can easily provide intellisense while defining bindings in XAML. In this example, the code behind declares a property called AProperty. Normally intellisense does not include candidate properties while declaring bindings, for example...

AProperty is not in the proposed values

All you have to do is define a design-time data context at the top of the page. Then suitable properties are included in the candidate list. It's done with the d:DataContext line below. If you have a local namespace defined then use 

d:DataContext="{d:DesignInstance local:<classname>}"

otherwise you can use 

d:DataContext="{d:DesignInstance <namespace>:<classname>}" 

where <namespace> is the last segment of your class namespace (lower-case)


AProperty is now in the candidate list


No comments:

Post a Comment