diff --git a/src/Calculator/Views/TitleBar.xaml b/src/Calculator/Views/TitleBar.xaml
index 6e2bded5..bcbe7d46 100644
--- a/src/Calculator/Views/TitleBar.xaml
+++ b/src/Calculator/Views/TitleBar.xaml
@@ -12,8 +12,7 @@
Height="32"
HorizontalAlignment="Stretch">
+ Background="Transparent">
@@ -31,7 +30,6 @@
VerticalAlignment="Center"
Foreground="{ThemeResource TitleBarForegroundBaseHighBrush}"
FontSize="12"
- TextAlignment="Left"
TextTrimming="CharacterEllipsis"
Visibility="{x:Bind ApplicationViewModel.IsAlwaysOnTop, Converter={StaticResource BooleanToVisibilityNegationConverter}, Mode=OneWay}"/>
diff --git a/src/Calculator/Views/TitleBar.xaml.cpp b/src/Calculator/Views/TitleBar.xaml.cpp
index c4dcb95e..e5f85c80 100644
--- a/src/Calculator/Views/TitleBar.xaml.cpp
+++ b/src/Calculator/Views/TitleBar.xaml.cpp
@@ -11,6 +11,7 @@ using namespace Platform;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Foundation;
+using namespace Windows::System::Profile;
using namespace Windows::UI;
using namespace Windows::UI::Core;
using namespace Windows::UI::ViewManagement;
@@ -45,13 +46,13 @@ namespace CalculatorApp
void TitleBar::OnLoaded(_In_ Object ^ /*sender*/, _In_ RoutedEventArgs ^ /*e*/)
{
+ auto that(this);
// Register events
m_visibilityChangedToken = m_coreTitleBar->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->LayoutRoot->Height = cTitleBar->Height;
- this->SetTitleBarPadding();
+ ref new TypedEventHandler([that](CoreApplicationViewTitleBar ^ cTitleBar, Object ^) {
+ that->SetTitleBarHeightAndPadding();
});
m_colorValuesChangedToken = m_uiSettings->ColorValuesChanged += ref new TypedEventHandler(this, &TitleBar::ColorValuesChanged);
@@ -60,11 +61,15 @@ namespace CalculatorApp
m_windowActivatedToken = Window::Current->Activated +=
ref new Windows::UI::Xaml::WindowActivatedEventHandler(this, &CalculatorApp::TitleBar::OnWindowActivated);
// Set properties
- LayoutRoot->Height = m_coreTitleBar->Height;
SetTitleBarControlColors();
+ SetTitleBarHeightAndPadding();
- SetTitleBarVisibility();
- SetTitleBarPadding();
+ // 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*/)
@@ -82,14 +87,20 @@ namespace CalculatorApp
m_windowActivatedToken.Value = 0;
}
-
- void TitleBar::SetTitleBarVisibility()
+ void TitleBar::SetTitleBarVisibility(bool forceDisplay)
{
- this->LayoutRoot->Visibility = m_coreTitleBar->IsVisible || ApplicationViewModel->IsAlwaysOnTop ? ::Visibility::Visible : ::Visibility::Collapsed;
+ this->LayoutRoot->Visibility =
+ forceDisplay || m_coreTitleBar->IsVisible || ApplicationViewModel->IsAlwaysOnTop ? ::Visibility::Visible : ::Visibility::Collapsed;
}
- void TitleBar::SetTitleBarPadding()
+ void TitleBar::SetTitleBarHeightAndPadding()
{
+ if (m_coreTitleBar->Height == 0)
+ {
+ // The titlebar isn't init
+ return;
+ }
+
double leftAddition = 0;
double rightAddition = 0;
@@ -105,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()
@@ -161,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);
}));
}
diff --git a/src/Calculator/Views/TitleBar.xaml.h b/src/Calculator/Views/TitleBar.xaml.h
index ae5e2d61..eec5cf00 100644
--- a/src/Calculator/Views/TitleBar.xaml.h
+++ b/src/Calculator/Views/TitleBar.xaml.h
@@ -26,9 +26,8 @@ public
void OnLoaded(_In_ Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void OnUnloaded(_In_ Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
- void SetTitleBarText(Platform::String ^ text);
- void SetTitleBarVisibility();
- 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);