Dependency property and value inheritance

Published Mon, Jan 18 2010 12:36

In the previous post, I’ve talked a little bit about dependency properties and on how they’re defined. One of the advantages of using those properties is value inheritance. Take a look at the following snippet:

<UserControl x:Class="Tests.MainPage"
    xmlns=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" FontSize="30"> <StackPanel> <TextBlock FontSize="20">Hello there!</TextBlock> <ListBox> <ListBoxItem FontSize="12" Content=" Item 1" /> <ListBoxItem Content="Item 2" /> </ListBox> <Button Content="Say Hi!!!" /> <Button Content="Say Hi2!!!" FontSize="50" /> </StackPanel> </UserControl>

If you run the previous sample, you’ll notice that the elements that don’t override the FontSize dependency property end up inheriting the value of its parent’s property value. This is one of the advantages of using this kind of property in Silverlight and WPF. Do notice that unlike WPF, where you can opt in to value inheritance by passing FrameworkPropertyMetadataOptions.Inherits to the metadata info you use during the dependency property definition (register method call), in Silverlight there’s not way to influence this behavior.

And that’s it for now. Stay tuned for more about Silverlight.

Filed under:

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above:  

Search

This Blog

Tags

Community

Archives

Syndication

Email Notifications

News




  • View Luis Abreu's profile on LinkedIn


    Follow me at Twitter

    My books

    Silverlight 4.0: Curso Completo

    ASP.NET 4.0: Curso Completo

    Portuguese LINQ book cover

    Portuguese ASP.NET 3.5 book cover

    Portuguese ASP.NET AJAX book cover

    Portuguese ASP.NET AJAX book cover