Hi,@尼龟 杰. Welcome Microsoft Q&A.
You could try the solution below to see if it is what you want. If so, you can refer to it and modify your code.
app.xaml:
<Application x:Class="WpfApp2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp2"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:sysw="clr-namespace:System.Windows;assembly=PresentationFramework"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<sysw:Thickness x:Key="AppBorderThickness">3</sysw:Thickness>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
MainWindow.xaml:
<Window.Resources>
<Style x:Key="btn" TargetType="{x:Type Button}">
<Setter Property="BorderThickness" Value="{DynamicResource AppBorderThickness}" />
</Style>
</Window.Resources>
<Grid>
<Button Style="{StaticResource btn}" Width="200" Height="100" Content="My Button"/>
</Grid>
MainWindow.xaml.cs:
public MainWindow()
{
InitializeComponent();
App app = App.Current as App;
app.Resources["AppBorderThickness"] = new Thickness(7);
}
The result:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.