Here is the foreground code:
<Window.Resources>
<textblock x:key= "res1" text= "good study"/>
<textblock x:key= "Res2" text= "good study"/>
</Window.Resources>
<Grid>
<wrappanel orientation= "Vertical" >
<button content= "{StaticResource res1}"/>
<button content= "{DynamicResource res2}"/>
<button content= "Update" click= "Button_Click"/>
</WrapPanel>
</Grid>
We do different references, both dynamic and static.
Here is the background code:
private void Button_Click (object sender, RoutedEventArgs e)
{
resources["res1"] = new TextBlock {Text = "day Up"};
resources["Res2"] = new TextBlock {Text = "day Up"};
}
Result: The dynamic resource updates the resource after clicking the Update button, stating that the static resource is only loaded the first time the form is loaded,
Dynamic resources can be updated as resources change.
wpfの Static Resources (StaticResource) and dynamic resources (DynamicResource)