WPF: Static and Dynamic Resources and Resource Dictionary
Static versus dynamic resources
We often use styles or control templates placed in the middle, like this:
Static and dynamic resources are used as follows:
<>
<SolidColorBrush x:Key="SolidColor" Color="#FF0000" />
</>
<Grid>
<StackPanel>
<Button Height="40" Margin="10" Content="Button1" Click="Button_Click" />
<Button Height="40"
Margin="10"
Content="Button2"
BorderBrush="{StaticResource SolidColor}"
BorderThickness="4" />
<Button Height="40"
Margin="10"
Content="Button3"
BorderBrush="{DynamicResource SolidColor}"
BorderThickness="4" />
</StackPanel>
</Grid>
Difference: Dynamic resources can be changed in the interface according to the instructions, static does not.
resource dictionary
When the style more, this time we need to create a separate resource to manage him, this time we have a resource dictionary:
Port the code in:
This time it is also necessary to load this resource dictionary at load time, in the middle of loading the
The corresponding resource can also be found in main as follows:
The results are still available: