Using dynamic logical resources in WPF
In the previous recipe, we learned how to use logical resources using the StaticResource
markup extension. In this recipe, we will learn how to use logical resources using the DynamicResource
markup extension and will also learn the difference between them.
Getting ready
Get started by creating a new project. Open the Visual Studio IDE and create a new WPF application project called CH07.DynamicResourceDemo
.
How to do it...
Follow these steps to use logical resources dynamically and modify the values of the resource as per the need:
- Open the
MainWindow.xaml
file and replace theGrid
with aStackPanel
. - Add a border inside the
StackPanel
and set its dimensions. - Add another
StackPanel
inside the panel and add a group of three radio buttons inside it. Label them asRed
,Green
, andBlue
. Here's the complete XAML code:
<StackPanel Orientation="Horizontal"> <Border Height="80" Width="150" Margin="8"/> <StackPanel...