Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better active/inactive window title color handling #1324

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ public class BorderlessWindowBehavior : Behavior<Window>
private HwndSource hwndSource;
private WindowChrome windowChrome;
private Thickness? savedBorderThickness = null;
private Brush nonActiveBorderColor;
private Brush savedBorderBrush = null;

protected override void OnAttached()
{
// maybe this can change to set via window from a dependency property
this.nonActiveBorderColor = new SolidColorBrush(Colors.Gray);
this.nonActiveBorderColor.Freeze();

windowChrome = new WindowChrome();
windowChrome.ResizeBorderThickness = SystemParameters2.Current.WindowResizeBorderThickness;
windowChrome.CaptionHeight = 0;
Expand Down Expand Up @@ -67,7 +61,6 @@ protected override void OnAttached()
AssociatedObject.SourceInitialized += AssociatedObject_SourceInitialized;
AssociatedObject.StateChanged += AssociatedObject_StateChanged;
AssociatedObject.Activated += AssociatedObject_Activated;
AssociatedObject.Deactivated += AssociatedObject_Deactivated;

// handle resize mode after loading the window
System.ComponentModel.DependencyPropertyDescriptor.FromProperty(Window.ResizeModeProperty, typeof(Window))
Expand Down Expand Up @@ -139,7 +132,6 @@ private void Cleanup()
AssociatedObject.SourceInitialized -= AssociatedObject_SourceInitialized;
AssociatedObject.StateChanged -= AssociatedObject_StateChanged;
AssociatedObject.Activated -= AssociatedObject_Activated;
AssociatedObject.Deactivated -= AssociatedObject_Deactivated;
if (hwndSource != null)
{
hwndSource.RemoveHook(WindowProc);
Expand Down Expand Up @@ -201,22 +193,9 @@ private System.IntPtr WindowProc(System.IntPtr hwnd, int msg, System.IntPtr wPar

private void AssociatedObject_Activated(object sender, EventArgs e)
{
if (savedBorderBrush != null)
{
AssociatedObject.BorderBrush = savedBorderBrush;
}
HandleMaximize();
}

private void AssociatedObject_Deactivated(object sender, EventArgs e)
{
if (AssociatedObject.BorderBrush != null)
{
savedBorderBrush = AssociatedObject.BorderBrush;
AssociatedObject.BorderBrush = this.nonActiveBorderColor;
}
}

private void AssociatedObject_StateChanged(object sender, EventArgs e)
{
HandleMaximize();
Expand Down Expand Up @@ -402,12 +381,6 @@ private void AssociatedObject_Loaded(object sender, RoutedEventArgs e)

// handle resize mode
this.HandleResizeMode(window, window.ResizeMode);

// non-active border brush
if (window.NonActiveBorderBrush != null)
{
this.nonActiveBorderColor = window.NonActiveBorderBrush;
}
}

public static readonly DependencyProperty EnableDWMDropShadowProperty = DependencyProperty.Register("EnableDWMDropShadow", typeof(bool), typeof(BorderlessWindowBehavior), new PropertyMetadata(false));
Expand Down
18 changes: 0 additions & 18 deletions MahApps.Metro/Controls/MetroWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ public class MetroWindow : Window
private Storyboard overlayStoryboard;
Rectangle flyoutModal;

private Brush savedTitleBarBrush = null;

public static readonly RoutedEvent FlyoutsStatusChangedEvent = EventManager.RegisterRoutedEvent(
"FlyoutsStatusChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MetroWindow));

Expand Down Expand Up @@ -574,22 +572,6 @@ public void HideOverlay()
public MetroWindow()
{
Loaded += this.MetroWindow_Loaded;
Activated += MetroWindow_Activated;
Deactivated += MetroWindow_Deactivated;
}

private void MetroWindow_Activated(object sender, EventArgs e)
{
if (savedTitleBarBrush != null)
{
WindowTitleBrush = savedTitleBarBrush;
}
}

private void MetroWindow_Deactivated(object sender, EventArgs e)
{
savedTitleBarBrush = WindowTitleBrush;
WindowTitleBrush = NonActiveWindowTitleBrush;
}

private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
Expand Down
10 changes: 10 additions & 0 deletions MahApps.Metro/Themes/MetroWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@
</Storyboard>
</ControlTemplate.Resources>
<ControlTemplate.Triggers>
<!-- handle active/inactive state -->
<Trigger Property="IsActive"
Value="False">
<Setter TargetName="PART_WindowTitleBackground"
Property="Fill"
Value="{Binding Path=NonActiveWindowTitleBrush, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}" />
<Setter TargetName="PART_Border"
Property="BorderBrush"
Value="{Binding Path=NonActiveBorderBrush, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}" />
</Trigger>
<!-- no icon and no icon content template -> collapse the icon content control -->
<MultiTrigger>
<MultiTrigger.Conditions>
Expand Down