diff --git a/src/Calculator/Views/TitleBar.xaml b/src/Calculator/Views/TitleBar.xaml index cc5120be..98e6d045 100644 --- a/src/Calculator/Views/TitleBar.xaml +++ b/src/Calculator/Views/TitleBar.xaml @@ -27,7 +27,6 @@ IsVisibleChanged += ref new TypedEventHandler( - [this](CoreApplicationViewTitleBar ^ cTitleBar, Object ^) { this->SetTitleBarVisibility(); }); + [that](CoreApplicationViewTitleBar ^ cTitleBar, Object ^) { that->SetTitleBarVisibility(false); }); m_layoutChangedToken = m_coreTitleBar->LayoutMetricsChanged += - ref new TypedEventHandler([this](CoreApplicationViewTitleBar ^ cTitleBar, Object ^) { - this->SetTitleBarHeight(); - this->SetTitleBarPadding(); + ref new TypedEventHandler([that](CoreApplicationViewTitleBar ^ cTitleBar, Object ^) { + that->SetTitleBarHeightAndPadding(); }); m_colorValuesChangedToken = m_uiSettings->ColorValuesChanged += ref new TypedEventHandler(this, &TitleBar::ColorValuesChanged); @@ -60,10 +61,15 @@ namespace CalculatorApp m_windowActivatedToken = Window::Current->Activated += ref new Windows::UI::Xaml::WindowActivatedEventHandler(this, &CalculatorApp::TitleBar::OnWindowActivated); // Set properties - this->SetTitleBarHeight(); - this->SetTitleBarControlColors(); - this->SetTitleBarVisibility(); - this->SetTitleBarPadding(); + SetTitleBarControlColors(); + SetTitleBarHeightAndPadding(); + + // As of Windows 10 1903: when an app runs on a PC (without Tablet mode activated) + // properties of CoreApplicationViewTitleBar aren't initialized during the first seconds after launch. + auto forceDisplay = AnalyticsInfo::VersionInfo->DeviceFamily == L"Windows.Desktop" + && UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Mouse; + + SetTitleBarVisibility(forceDisplay); } void TitleBar::OnUnloaded(_In_ Object ^ /*sender*/, _In_ RoutedEventArgs ^ /*e*/) @@ -81,18 +87,20 @@ namespace CalculatorApp m_windowActivatedToken.Value = 0; } - void TitleBar::SetTitleBarVisibility() + void TitleBar::SetTitleBarVisibility(bool forceDisplay) { - this->LayoutRoot->Visibility = m_coreTitleBar->IsVisible || IsAlwaysOnTopMode ? ::Visibility::Visible : ::Visibility::Collapsed; + this->LayoutRoot->Visibility = + forceDisplay || m_coreTitleBar->IsVisible || IsAlwaysOnTopMode ? ::Visibility::Visible : ::Visibility::Collapsed; } - void TitleBar::SetTitleBarHeight() + void TitleBar::SetTitleBarHeightAndPadding() { - this->LayoutRoot->Height = m_coreTitleBar->Height; - } + if (m_coreTitleBar->Height == 0) + { + // The titlebar isn't init + return; + } - void TitleBar::SetTitleBarPadding() - { double leftAddition = 0; double rightAddition = 0; @@ -108,11 +116,13 @@ namespace CalculatorApp } this->LayoutRoot->Padding = Thickness(leftAddition, 0, rightAddition, 0); + this->LayoutRoot->Height = m_coreTitleBar->Height; } void TitleBar::ColorValuesChanged(_In_ UISettings ^ /*sender*/, _In_ Object ^ /*e*/) { - Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]() { SetTitleBarControlColors(); })); + auto that(this); + Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([that]() { that->SetTitleBarControlColors(); })); } void TitleBar::SetTitleBarControlColors() @@ -164,9 +174,10 @@ namespace CalculatorApp void TitleBar::OnHighContrastChanged(_In_ AccessibilitySettings ^ /*sender*/, _In_ Object ^ /*args*/) { - Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]() { - SetTitleBarControlColors(); - SetTitleBarVisibility(); + auto that(this); + Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([that]() { + that->SetTitleBarControlColors(); + that->SetTitleBarVisibility(false); })); } @@ -178,7 +189,7 @@ namespace CalculatorApp void TitleBar::OnIsAlwaysOnTopModePropertyChanged(bool /*oldValue*/, bool newValue) { - SetTitleBarVisibility(); + SetTitleBarVisibility(false); VisualStateManager::GoToState(this, newValue ? "AOTMiniState" : "AOTNormalState", false); } diff --git a/src/Calculator/Views/TitleBar.xaml.h b/src/Calculator/Views/TitleBar.xaml.h index d4cb2883..27d05b96 100644 --- a/src/Calculator/Views/TitleBar.xaml.h +++ b/src/Calculator/Views/TitleBar.xaml.h @@ -27,9 +27,8 @@ public void OnLoaded(_In_ Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void OnUnloaded(_In_ Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); - void SetTitleBarVisibility(); - void SetTitleBarHeight(); - void SetTitleBarPadding(); + void SetTitleBarVisibility(bool forceDisplay); + void SetTitleBarHeightAndPadding(); void SetTitleBarControlColors(); void ColorValuesChanged(_In_ Windows::UI::ViewManagement::UISettings ^ sender, _In_ Platform::Object ^ e); void OnHighContrastChanged(Windows::UI::ViewManagement::AccessibilitySettings ^ sender, Platform::Object ^ args);