Using static logical resources in WPF
Logical resources in WPF are the objects that can be shared and reused across some part of a Visual Tree or an entire application. These can be colors, brushes, geometrics, styles, or any other .NET objects (int
, string
, List<T>
, T
, and more) defined by the .NET Framework or developer. These objects are typically placed inside a ResourceDictionary
.
In this recipe, we will learn how to use logical resources using the binding key StaticResource
.
Getting ready
Make sure that Visual Studio is running. Create a project called CH07.StaticResourceDemo
, based on the WPF application template.
How to do it...
Follow these steps to create a logical resource and use it inside the application window:
- Open the
MainWindow.xaml
file and replace theGrid
with a horizontalStackPanel
. - Insert a
Border
control inside theStackPanel
. Set itsHeight
andWidth
properties to80
and150,
respectively:
<Border Height="80" Width="150" Margin="8"> </Border...