DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Creating an Intellisense Compatible Enum-Based Dependency Property

Creating an Intellisense Compatible Enum-Based Dependency Property

Tim Dams user avatar by
Tim Dams
·
Jun. 02, 12 · Mobile Zone · Interview
Like (0)
Save
Tweet
4.07K Views

Join the DZone community and get the full member experience.

Join For Free

actually, 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:

public enum graphtypes {default, point, line}

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):

public static readonly dependencyproperty graphtypeproperty =
    dependencyproperty.register("graphtype", typeof (graphtypes), typeof (graphcontrol), new propertymetadata(graphtypes.default));

public graphtypes graphtype
{
    get { return (graphtypes) getvalue(graphtypeproperty); }
    set { setvalue(graphtypeproperty, value); }
}

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.

Property (programming) Dependency

Published at DZone with permission of Tim Dams, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Why I'm Choosing Pulumi Over Terraform
  • Debugging Deadlocks and Race Conditions
  • Why Great Money Doesn’t Retain Great Devs w/ Stack Overflow, DataStax & Reprise
  • 10 Books Every Senior Engineer Should Read

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo