Skip to content

Commit

Permalink
Fix broken window border when inactive in win7
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Jul 19, 2024
1 parent a101ca0 commit 5272d37
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
45 changes: 43 additions & 2 deletions source/iNKORE.UI.WPF.Modern/Controls/Helpers/WindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,12 @@ private static void OnAcrylic10ColorChanged(DependencyObject d, DependencyProper

private static void OnCornerStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is Window)
CornerHelper.SetWindowCorners((Window)d, (WindowCornerStyle)e.NewValue);
if (d is Window window)
{
CornerHelper.SetWindowCorners(window, (WindowCornerStyle)e.NewValue);
UpdateShouldDisplayManualBorder(window);

}
}

public static WindowCornerStyle GetCornerStyle(Window window)
Expand Down Expand Up @@ -329,6 +333,42 @@ public static void SetApplyNoise(Window window, bool value)
}


#endregion

#region ShouldDisplayManualBorder

public static readonly DependencyPropertyKey ShouldDisplayManualBorderPropertyKey =
DependencyProperty.RegisterAttachedReadOnly(
"ShouldDisplayManualBorder",
typeof(bool),
typeof(WindowHelper),
new PropertyMetadata(false));

public static readonly DependencyProperty ShouldDisplayManualBorderProperty = ShouldDisplayManualBorderPropertyKey.DependencyProperty;

public static bool GetShouldDisplayManualBorder(Window window)
{
return (bool)window.GetValue(ShouldDisplayManualBorderProperty);
}

private static void SetShouldDisplayManualBorder(Window window, bool value)
{
window.SetValue(ShouldDisplayManualBorderPropertyKey, value);
}

public static void UpdateShouldDisplayManualBorder(Window window)
{
if (window == null)
{
return;
}

var isOsBorderPresent = OSVersionHelper.IsWindows11OrGreater;

var newValue = !isOsBorderPresent;
SetShouldDisplayManualBorder(window, newValue);
}

#endregion


Expand Down Expand Up @@ -493,6 +533,7 @@ void onLoaded(object sender, RoutedEventArgs e)
}

UpdateWindowChrome(window);
UpdateShouldDisplayManualBorder(window);
}


Expand Down
11 changes: 7 additions & 4 deletions source/iNKORE.UI.WPF.Modern/Themes/Controls/Window.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<Setter Property="Foreground" Value="{DynamicResource SystemControlPageTextBaseHighBrush}" />
<Setter Property="Background" Value="{DynamicResource ApplicationPageBackgroundThemeBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource WindowBorder}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="UseLayoutRounding" Value="True" />
Expand Down Expand Up @@ -165,18 +165,18 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Background" Value="Transparent">
<Setter TargetName="LayoutRoot" Property="BorderThickness" Value="0" />
<!--<Setter TargetName="LayoutRoot" Property="BorderThickness" Value="0" />-->
</Trigger>
<Trigger Property="IsActive" Value="False">
<Setter TargetName="LayoutRoot" Property="BorderBrush" Value="{DynamicResource WindowBorderInactive}" />
<Setter TargetName="WindowBorder" Property="BorderBrush" Value="{DynamicResource WindowBorderInactive}" />
<Setter TargetName="HighContrastBorder" Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.InactiveCaptionBrushKey}}" />
</Trigger>
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="true">
<Setter TargetName="ContentGrid" Property="Margin" Value="7,0,7,7" />
<Setter TargetName="HighContrastBorder" Property="Visibility" Value="Visible" />
</DataTrigger>
<Trigger Property="WindowState" Value="Maximized">
<Setter TargetName="LayoutRoot" Property="BorderThickness" Value="0" />
<Setter TargetName="WindowBorder" Property="BorderThickness" Value="0" />
<Setter TargetName="ContentGrid" Property="Margin" Value="0" />
<Setter TargetName="HighContrastBorder" Property="Visibility" Value="Collapsed" />
</Trigger>
Expand Down Expand Up @@ -217,6 +217,9 @@
<Trigger Property="WindowChrome.WindowChrome" Value="{x:Null}">
<Setter Property="chelper:WindowHelper.FixMaximizedWindow" Value="False" />
</Trigger>
<Trigger Property="chelper:WindowHelper.ShouldDisplayManualBorder" Value="True">
<Setter Property="BorderThickness" Value="1" />
</Trigger>
</Style.Triggers>
</Style>

Expand Down

0 comments on commit 5272d37

Please sign in to comment.