Accessing a static property from XAML

XAML provides an easy way to set values of properties—type converters and the extended property syntax allow for flexible setting of values. However, some things cannot be expressed as a simple value, such as setting a property to the value of some static property.

Getting ready

Make sure Visual Studio is up and running.

How to do it...

We'll create an application that uses a static property from within XAML:

  1. Create a new WPF Application named CH01.StaticProperties.
  2. Open MainWindow.xaml. Replace the Grid element with a StackPanel.
  3. Add some shapes as shown in the following code block:
        <StackPanel>
            <Ellipse Stroke="Black" Height="50" />
            <Rectangle Stroke="Black" Height="50" />
        </StackPanel>
  4. Suppose we want to fill the ...

Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.