Using static bindings
Often, we use static properties in our applications. Along with WPF 4.5, Microsoft provided us with the option to use static properties in XAML markup, while performing data binding. In this recipe, we will learn how to create such bindings. These can be useful in the next recipes while using Converters, Styles, and Templates.
Getting ready
Let's start by creating a new project, called CH04.StaticBindingDemo
. Open your Visual Studio IDE and select the WPF application project as the project template.
How to do it...
Once the project has been created, perform the following steps to learn static binding:
- Open the
MainWindow.xaml
page and add aLabel
inside theGrid
panel. Give it a background color (let's say,OrangeRed
) and run the application. This is what we use most often to write hardcoded values inline:
<Label Background="OrangeRed" Content="Kunal Chowdhury" FontSize="25" Width="300" Height="60" Padding="10" Margin="10"/>
- Now, let...