Property elements in WPF: XAML

As we know XAML allows us to define properties of elements using the attribute syntax. It means that,for example, if we want to specify the content/background colour of button control than we can specify it using attributes as shown below:

<Button Content="Attribute Style" Background = "Yellow"/>

However there might be a challenge using this syntax. Consider a scenario where we want to display a rectangle inside the button. In this case it would not be possible to define a rectangle in the content attribute.This will be due to string restrictions of attribute syntax. To overcome this kind of scenarios, XAML provides the Property elements.

The syntax of property element is . So now we can provide a child tag under the Button tag to define the rectangle inside the button. The code would be

            <Rectangle Height="40" Width="40" Fill="Yellow"/>

Please note how beautifully the rectangle tag is given as child tag for Button.

kick it on

Shout it

DZoneDeliciousLinkedInRedditTechnorati FavoritesStumbleUponShare


  1. Property elements in WPF: XAML…

    You’ve been kicked (a good thing) – Trackback from…

  2. Property elements in WPF: XAML | Tech Samosa…

    Thank you for submitting this cool story – Trackback from DotNetShoutout…

  3. [...] it using attributes as shown below: However there might be a challenge using this syntax…. Read more… Categories: .NET  XAML     Share | Related [...]

  4. Hello,

    Thank for this interesting post !

    Getting the same behavior from code may interest you too:


Leave a Reply

Your email address will not be published. Required fields are marked *