Based on the original OP example, they were almost there ...
When the window is maximized, Windows seems to ignore the value of ResizeBorderThickness. Using <Setter Property="Margin" Value="7"/> seems to work, but this value may need to be changed depending on the operating system (I tested this on Windows 10).
I recommend making a few small changes (see the code below), such as adding WindowStyle="None" and ResizeMode="CanResize" to the Window , as well as moving the Style to Window.Resources , Application.Resources or even to ResourceDictionary by changing the style of TargetType on "{x:Type Panel}" and using the key name (for example: x:Key="WindowMainPanelStyle" ), as this will prevent the style from automatically applying to any children of the Grid , and also allow the style to be used with all elements that inherit from Panel (e.g. Border , DockPanel , Grid , StackPanel , etc.).
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowStyle="None" ResizeMode="CanResize"> <WindowChrome.WindowChrome> <WindowChrome CaptionHeight="50" ResizeBorderThickness="5" /> </WindowChrome.WindowChrome> <Window.Resources> <Style TargetType="{x:Type Panel}" x:Key="WindowMainPanelStyle"> <Setter Property="Margin" Value="0" /> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=WindowState}" Value="Maximized"> <Setter Property="Margin" Value="7" /> </DataTrigger> </Style.Triggers> </Style> </Window.Resources> <Grid Style="{StaticResource WindowMainPanelStyle}"> <Border BorderThickness="2" BorderBrush="Blue" Background="Yellow" /> </Grid> </Window>
source share