Creating an IntelliSense Compatible Enum-Based Dependency Property
Join the DZone community and get the full member experience.
Join For Freeactually, this post has a way too fancy title , because in fact i will merely show that enum-based dependency properties are intellisense compatible “out-of-the-box”. (by the way, if you know all about dependcy properties: simply read the line in bold and you’ll know all there is to know).
when creating a (wp7/sl/wpf) usercontrol, one often ends up creating one more dependency properties (dp). most of the times you only want a discrete set of possible values that can be assigned to the dp. the logical choice then of course is to have an enum-based dp.
now, for the intellisense to work it is important that you define the enum type outside the usercontrols class. for example, suppose we have define the following enum:
now, all that remains is to add a dp that uses this enum (remember that you can use the ‘dependencyproperty’ snippet that comes with vs):
once you now add the usercontrol elsewhere in your xaml-code, intellisense will happily show what values can be assigned to the dp:
there we go. that’s all there was too it.
next post i’ll show how to create a wp7 user control to plot graphs using data binding. consider some of the code here a sneak preview.
Opinions expressed by DZone contributors are their own.
Comments