File tree Expand file tree Collapse file tree 3 files changed +26
-10
lines changed Expand file tree Collapse file tree 3 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -30,16 +30,22 @@ private void SetUWPTitleBar()
3030
3131 PART_DragRegion = GetTemplateChild ( nameof ( PART_DragRegion ) ) as Grid ;
3232 Window . Current . SetTitleBar ( PART_DragRegion ) ;
33+
34+ _isAutoConfigCompleted = true ;
3335 }
3436 }
3537
3638 private void ResetUWPTitleBar ( )
3739 {
38- CoreApplication . GetCurrentView ( ) . TitleBar . ExtendViewIntoTitleBar = false ;
39- Window . Current . Activated -= this . Current_Activated ;
40- SizeChanged -= this . TitleBar_SizeChanged ;
41- CoreApplication . GetCurrentView ( ) . TitleBar . LayoutMetricsChanged -= this . TitleBar_LayoutMetricsChanged ;
42- Window . Current . SetTitleBar ( null ) ;
40+ // Only reset if we were the ones who configured
41+ if ( _isAutoConfigCompleted )
42+ {
43+ CoreApplication . GetCurrentView ( ) . TitleBar . ExtendViewIntoTitleBar = false ;
44+ Window . Current . Activated -= this . Current_Activated ;
45+ SizeChanged -= this . TitleBar_SizeChanged ;
46+ CoreApplication . GetCurrentView ( ) . TitleBar . LayoutMetricsChanged -= this . TitleBar_LayoutMetricsChanged ;
47+ Window . Current . SetTitleBar ( null ) ;
48+ }
4349 }
4450
4551 private void Current_Activated ( object sender , Windows . UI . Core . WindowActivatedEventArgs e )
Original file line number Diff line number Diff line change @@ -76,6 +76,8 @@ private void SetWASDKTitleBar()
7676 // Recalculate the drag region for the custom title bar
7777 // if you explicitly defined new draggable areas.
7878 SetDragRegionForCustomTitleBar ( ) ;
79+
80+ _isAutoConfigCompleted = true ;
7981 }
8082 }
8183
@@ -108,11 +110,15 @@ private void ResetWASDKTitleBar()
108110 // TO DO: Throw exception that window has not been set?
109111 }
110112
111- Window . AppWindow . TitleBar . ExtendsContentIntoTitleBar = false ;
112- this . Window . SizeChanged -= Window_SizeChanged ;
113- this . Window . Activated -= Window_Activated ;
114- SizeChanged -= this . TitleBar_SizeChanged ;
115- Window . AppWindow . TitleBar . ResetToDefault ( ) ;
113+ // Only reset if we were the ones who configured
114+ if ( _isAutoConfigCompleted )
115+ {
116+ Window . AppWindow . TitleBar . ExtendsContentIntoTitleBar = false ;
117+ this . Window . SizeChanged -= Window_SizeChanged ;
118+ this . Window . Activated -= Window_Activated ;
119+ SizeChanged -= this . TitleBar_SizeChanged ;
120+ Window . AppWindow . TitleBar . ResetToDefault ( ) ;
121+ }
116122 }
117123
118124 private void Window_Activated ( object sender , WindowActivatedEventArgs args )
Original file line number Diff line number Diff line change @@ -67,6 +67,10 @@ public partial class TitleBar : Control
6767 ColumnDefinition ? PART_RightPaddingColumn ;
6868 StackPanel ? PART_ButtonHolder ;
6969
70+ // Internal tracking (if AutoConfigureCustomTitleBar is on) if we've actually setup the TitleBar yet or not
71+ // We only want to reset TitleBar configuration in app, if we're the TitleBar instance that's managing that state.
72+ private bool _isAutoConfigCompleted = false ;
73+
7074 public TitleBar ( )
7175 {
7276 this . DefaultStyleKey = typeof ( TitleBar ) ;
You can’t perform that action at this time.
0 commit comments