#119 – Read and Write Dependency Property Values from XAML or Code

You can read and write dependency property values in either XAML or code.

For example, if we implement dependency properties FirstName, LastName and Age in our Person class, we can set these properties from XAML:

        <m:Person x:Key="guy" FirstName="Samuel" LastName="Clemens"  Age="75"/>

We can also read or write these properties from our code:

            Person author = (Person)this.Resources["guy"];
            string info = string.Format("{0} {1}, aged {2}", author.FirstName, author.LastName, author.Age);

Because these properties are full-fledged WPF dependency properties, they support the normal range of dependency property functionality including data binding, property inheritance and change notification.

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #119 – Read and Write Dependency Property Values from XAML or Code

  1. Pingback: Tweets that mention #119 – Read and Write Dependency Property Values from XAML or Code « 2,000 Things You Should Know About WPF -- Topsy.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 131 other followers