Skip to content

Commit

Permalink
Merge branch 'main' into ribbon
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlodotexe authored Jul 22, 2024
2 parents 702d160 + 18901b6 commit 2f6a4ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
16 changes: 11 additions & 5 deletions components/TitleBar/src/TitleBar.UWP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@ private void SetUWPTitleBar()

PART_DragRegion = GetTemplateChild(nameof(PART_DragRegion)) as Grid;
Window.Current.SetTitleBar(PART_DragRegion);

_isAutoConfigCompleted = true;
}
}

private void ResetUWPTitleBar()
{
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;
Window.Current.Activated -= this.Current_Activated;
SizeChanged -= this.TitleBar_SizeChanged;
CoreApplication.GetCurrentView().TitleBar.LayoutMetricsChanged -= this.TitleBar_LayoutMetricsChanged;
Window.Current.SetTitleBar(null);
// Only reset if we were the ones who configured
if (_isAutoConfigCompleted)
{
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;
Window.Current.Activated -= this.Current_Activated;
SizeChanged -= this.TitleBar_SizeChanged;
CoreApplication.GetCurrentView().TitleBar.LayoutMetricsChanged -= this.TitleBar_LayoutMetricsChanged;
Window.Current.SetTitleBar(null);
}
}

private void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
Expand Down
16 changes: 11 additions & 5 deletions components/TitleBar/src/TitleBar.WASDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ private void SetWASDKTitleBar()
// Recalculate the drag region for the custom title bar
// if you explicitly defined new draggable areas.
SetDragRegionForCustomTitleBar();

_isAutoConfigCompleted = true;
}
}

Expand Down Expand Up @@ -108,11 +110,15 @@ private void ResetWASDKTitleBar()
// TO DO: Throw exception that window has not been set?
}

Window.AppWindow.TitleBar.ExtendsContentIntoTitleBar = false;
this.Window.SizeChanged -= Window_SizeChanged;
this.Window.Activated -= Window_Activated;
SizeChanged -= this.TitleBar_SizeChanged;
Window.AppWindow.TitleBar.ResetToDefault();
// Only reset if we were the ones who configured
if (_isAutoConfigCompleted)
{
Window.AppWindow.TitleBar.ExtendsContentIntoTitleBar = false;
this.Window.SizeChanged -= Window_SizeChanged;
this.Window.Activated -= Window_Activated;
SizeChanged -= this.TitleBar_SizeChanged;
Window.AppWindow.TitleBar.ResetToDefault();
}
}

private void Window_Activated(object sender, WindowActivatedEventArgs args)
Expand Down
4 changes: 4 additions & 0 deletions components/TitleBar/src/TitleBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public partial class TitleBar : Control
ColumnDefinition? PART_RightPaddingColumn;
StackPanel? PART_ButtonHolder;

// Internal tracking (if AutoConfigureCustomTitleBar is on) if we've actually setup the TitleBar yet or not
// We only want to reset TitleBar configuration in app, if we're the TitleBar instance that's managing that state.
private bool _isAutoConfigCompleted = false;

public TitleBar()
{
this.DefaultStyleKey = typeof(TitleBar);
Expand Down

0 comments on commit 2f6a4ba

Please sign in to comment.