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

Fix TitleBar Sample mucking up App's TitleBar #556

Merged
merged 1 commit into from
Jul 22, 2024
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
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
Loading