diff --git a/src/Calculator/App.xaml b/src/Calculator/App.xaml
index 7eb3dac3..918034c0 100644
--- a/src/Calculator/App.xaml
+++ b/src/Calculator/App.xaml
@@ -19,7 +19,6 @@
#FF2B2B2B
-
@@ -55,7 +54,6 @@
#FFE0E0E0
-
@@ -89,7 +87,6 @@
2
-
diff --git a/src/Calculator/App.xaml.cpp b/src/Calculator/App.xaml.cpp
index 1a83fdb0..456b1e8c 100644
--- a/src/Calculator/App.xaml.cpp
+++ b/src/Calculator/App.xaml.cpp
@@ -233,12 +233,14 @@ void App::OnAppLaunch(IActivatedEventArgs^ args, String^ argument)
TraceLogger::GetInstance().LogOnAppLaunch(previousExecutionState.ToString()->Data());
-#if _DEBUG
- if (IsDebuggerPresent())
- {
- DebugSettings->EnableFrameRateCounter = true;
- }
-#endif
+ // Uncomment the following lines to display frame-rate and per-frame CPU usage info.
+ //#if _DEBUG
+ // if (IsDebuggerPresent())
+ // {
+ // DebugSettings->EnableFrameRateCounter = true;
+ // }
+ //#endif
+
auto userSettings = ref new Windows::UI::ViewManagement::UISettings();
m_isAnimationEnabled = userSettings->AnimationsEnabled;
diff --git a/src/Calculator/Calculator.vcxproj b/src/Calculator/Calculator.vcxproj
index d4023eda..9a3bbeb3 100644
--- a/src/Calculator/Calculator.vcxproj
+++ b/src/Calculator/Calculator.vcxproj
@@ -252,7 +252,6 @@
App.xaml
-
Views\Calculator.xaml
@@ -389,7 +388,6 @@
Create
Create
-
Views\Calculator.xaml
diff --git a/src/Calculator/Calculator.vcxproj.filters b/src/Calculator/Calculator.vcxproj.filters
index 4b8b9ed8..de3b3afb 100644
--- a/src/Calculator/Calculator.vcxproj.filters
+++ b/src/Calculator/Calculator.vcxproj.filters
@@ -278,9 +278,6 @@
-
- Common
-
Controls
@@ -290,7 +287,6 @@
Views\StateTriggers
-
@@ -302,6 +298,7 @@
Controls
+
@@ -368,9 +365,6 @@
Converters
-
- Common
-
Controls
@@ -380,7 +374,6 @@
Views\StateTriggers
-
@@ -392,6 +385,7 @@
Controls
+
@@ -450,15 +444,15 @@
Views
-
- Views
-
Views
Views
+
+ Views
+
diff --git a/src/Calculator/Common/TitleBarHelper.cpp b/src/Calculator/Common/TitleBarHelper.cpp
deleted file mode 100644
index 18e8be94..00000000
--- a/src/Calculator/Common/TitleBarHelper.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-#include "pch.h"
-#include "TitleBarHelper.h"
-#include "Converters/BooleanToVisibilityConverter.h"
-#include "CalcViewModel/ViewState.h"
-
-using namespace CalculatorApp::Common;
-using namespace CalculatorApp::Converters;
-using namespace Platform;
-using namespace std;
-using namespace Windows::ApplicationModel::Core;
-using namespace Windows::Foundation;
-using namespace Windows::UI::Xaml;
-
-unique_ptr TitleBarHelper::CreateTitleBarHelperIfNotDocked(FrameworkElement^ customTitleBar)
-{
- return (App::GetAppViewState() == ViewState::DockedView)
- ? nullptr
- : CalculatorApp::Common::TitleBarHelper::CreateTitleBarHelper(customTitleBar);
-}
-
-unique_ptr TitleBarHelper::CreateTitleBarHelper(_In_ FrameworkElement^ customTitleBar)
-{
- assert(customTitleBar != nullptr);
- if (customTitleBar != nullptr)
- {
- CoreApplicationViewTitleBar^ coreTitleBar = CoreApplication::GetCurrentView()->TitleBar;
- assert(coreTitleBar != nullptr);
- if (coreTitleBar != nullptr)
- {
- return make_unique(coreTitleBar, customTitleBar);
- }
- }
-
- return nullptr;
-}
-
-TitleBarHelper::TitleBarHelper(_In_ CoreApplicationViewTitleBar^ coreTitleBar, _In_ FrameworkElement^ customTitleBar) :
- m_coreTitleBar(coreTitleBar),
- m_customTitleBar(customTitleBar)
-{
- RegisterForLayoutChanged();
- RegisterForVisibilityChanged();
- SetCustomTitleBar();
-}
-
-TitleBarHelper::~TitleBarHelper()
-{
- m_coreTitleBar->LayoutMetricsChanged -= m_layoutChangedToken;
- m_coreTitleBar->IsVisibleChanged -= m_visibilityChangedToken;
-}
-
-void TitleBarHelper::SetTitleBarHeight(double height)
-{
- m_customTitleBar->Height = height;
-}
-
-void TitleBarHelper::SetTitleBarVisibility(bool isVisible)
-{
- m_customTitleBar->Visibility = BooleanToVisibilityConverter::Convert(isVisible);
-}
-
-void TitleBarHelper::RegisterForLayoutChanged()
-{
- m_layoutChangedToken =
- m_coreTitleBar->LayoutMetricsChanged += ref new TypedEventHandler(
- [this](CoreApplicationViewTitleBar^ cTitleBar, Object^)
- {
- // Update title bar control size as needed to account for system size changes
- SetTitleBarHeight(cTitleBar->Height);
- });
-}
-
-void TitleBarHelper::RegisterForVisibilityChanged()
-{
- m_visibilityChangedToken =
- m_coreTitleBar->IsVisibleChanged += ref new TypedEventHandler(
- [this](CoreApplicationViewTitleBar^ cTitleBar, Object^)
- {
- // Update title bar visibility
- SetTitleBarVisibility(cTitleBar->IsVisible);
- });
-}
-
-void TitleBarHelper::SetCustomTitleBar()
-{
- // Set custom XAML Title Bar
- m_coreTitleBar->ExtendViewIntoTitleBar = true;
- SetTitleBarHeight(m_coreTitleBar->Height);
- SetTitleBarVisibility(m_coreTitleBar->IsVisible);
- Window::Current->SetTitleBar(m_customTitleBar);
-}
diff --git a/src/Calculator/Common/TitleBarHelper.h b/src/Calculator/Common/TitleBarHelper.h
deleted file mode 100644
index d90ecd54..00000000
--- a/src/Calculator/Common/TitleBarHelper.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-#pragma once
-
-namespace CalculatorApp
-{
- namespace Common
- {
- class TitleBarHelper
- {
- public:
- static std::unique_ptr CreateTitleBarHelperIfNotDocked(
- _In_ Windows::UI::Xaml::FrameworkElement^ customTitleBar);
-
- // Prefer CreateTitleBarHelper over constructing your own instance,
- // because Create* will nullcheck the parameters.
- static std::unique_ptr CreateTitleBarHelper(
- _In_ Windows::UI::Xaml::FrameworkElement^ customTitleBar);
-
- TitleBarHelper(
- _In_ Windows::ApplicationModel::Core::CoreApplicationViewTitleBar^ coreTitleBar,
- _In_ Windows::UI::Xaml::FrameworkElement^ customTitleBar);
- ~TitleBarHelper();
-
- void SetTitleBarHeight(double height);
- void SetTitleBarVisibility(bool isVisible);
-
- private:
- void RegisterForLayoutChanged();
- void RegisterForVisibilityChanged();
- void SetCustomTitleBar();
-
- Platform::Agile m_coreTitleBar;
- Windows::UI::Xaml::FrameworkElement^ m_customTitleBar;
- Windows::Foundation::EventRegistrationToken m_layoutChangedToken;
- Windows::Foundation::EventRegistrationToken m_visibilityChangedToken;
- };
- }
-}
diff --git a/src/Calculator/Views/Calculator.xaml b/src/Calculator/Views/Calculator.xaml
index 12546358..dffa3270 100644
--- a/src/Calculator/Views/Calculator.xaml
+++ b/src/Calculator/Views/Calculator.xaml
@@ -172,11 +172,6 @@
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTransitions="{TemplateBinding ContentTransitions}"/>
-
-
diff --git a/src/Calculator/Views/HistoryList.xaml b/src/Calculator/Views/HistoryList.xaml
index 5bac8a74..329b4215 100644
--- a/src/Calculator/Views/HistoryList.xaml
+++ b/src/Calculator/Views/HistoryList.xaml
@@ -12,8 +12,6 @@
x:Name="HistoryList"
AutomationProperties.AutomationId="HistoryList"
FlowDirection="LeftToRight"
- Loaded="HistoryList_Loaded"
- Unloaded="HistoryList_Unloaded"
mc:Ignorable="d">
@@ -93,7 +91,6 @@
-
@@ -105,11 +102,10 @@
-
+
-
-
+
@@ -120,7 +116,7 @@
-
+
@@ -171,10 +167,5 @@
Content=""
Visibility="{x:Bind Model.ItemSize, Mode=OneWay, Converter={StaticResource ItemSizeToVisibilityNegationConverter}}"/>
-
-
diff --git a/src/Calculator/Views/HistoryList.xaml.cpp b/src/Calculator/Views/HistoryList.xaml.cpp
index de4a96c4..35755275 100644
--- a/src/Calculator/Views/HistoryList.xaml.cpp
+++ b/src/Calculator/Views/HistoryList.xaml.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
@@ -40,19 +40,6 @@ HistoryList::HistoryList()
HistoryEmpty->FlowDirection = LocalizationService::GetInstance()->GetFlowDirection();
}
-void HistoryList::HistoryList_Loaded(Object^ sender, RoutedEventArgs^ e)
-{
- // When transitioning between docked and undocked view states, the history list is
- // unloaded and then loaded, so we attempt to create the titlebarhelper every time
- // we are loaded, letting the util function check if we are docked or not.
- m_titleBarHelper = TitleBarHelper::CreateTitleBarHelperIfNotDocked(CustomTitleBar);
-}
-
-void HistoryList::HistoryList_Unloaded(Object^ sender, RoutedEventArgs^ e)
-{
- m_titleBarHelper = nullptr;
-}
-
void HistoryList::ListView_ItemClick(_In_ Object^ sender, _In_ ItemClickEventArgs^ e)
{
HistoryViewModel^ historyVM = static_cast(this->DataContext);
diff --git a/src/Calculator/Views/HistoryList.xaml.h b/src/Calculator/Views/HistoryList.xaml.h
index f4e44399..b9b12194 100644
--- a/src/Calculator/Views/HistoryList.xaml.h
+++ b/src/Calculator/Views/HistoryList.xaml.h
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
@@ -9,7 +9,6 @@
#pragma once
#include "Views/HistoryList.g.h"
-#include "Common/TitleBarHelper.h"
#include "Converters/ItemSizeToVisibilityConverter.h"
#include "Converters/VisibilityNegationConverter.h"
#include "CalcViewModel/HistoryViewModel.h"
@@ -38,10 +37,5 @@ namespace CalculatorApp
void ListView_ItemClick(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Controls::ItemClickEventArgs^ e);
void OnDeleteMenuItemClicked(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void OnDeleteSwipeInvoked(_In_ Microsoft::UI::Xaml::Controls::SwipeItem^ sender, _In_ Microsoft::UI::Xaml::Controls::SwipeItemInvokedEventArgs^ e);
-
- void HistoryList_Loaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
- void HistoryList_Unloaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
-
- std::unique_ptr m_titleBarHelper;
};
}
diff --git a/src/Calculator/Views/MainPage.xaml b/src/Calculator/Views/MainPage.xaml
index 534bf228..6f719aa8 100644
--- a/src/Calculator/Views/MainPage.xaml
+++ b/src/Calculator/Views/MainPage.xaml
@@ -13,7 +13,6 @@
x:Name="PageRoot"
Background="{ThemeResource AppChromeAcrylicHostBackdropMediumLowBrush}"
Loaded="OnPageLoaded"
- Unloaded="OnPageUnLoaded"
mc:Ignorable="d">
@@ -38,11 +37,6 @@
-
-
@@ -89,14 +83,11 @@
Command="{x:Bind Model.PasteCommand}"/>
-
-
+
PropertyChanged += ref new PropertyChangedEventHandler(this, &MainPage::OnAppPropertyChanged);
@@ -83,7 +80,7 @@ MainPage::MainPage() :
{
DisplayInformation::AutoRotationPreferences = DisplayOrientations::Portrait | DisplayOrientations::PortraitFlipped;
}
- }
+ }
}
void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
@@ -184,7 +181,6 @@ void MainPage::OnAppPropertyChanged(_In_ Platform::Object^ sender, _In_ Windows:
ShowHideControls(newValue);
UpdateViewState();
- SetTitleBarControlColors();
SetDefaultFocus();
}
else if (propertyName == ApplicationViewModel::CategoryNamePropertyName)
@@ -199,7 +195,7 @@ void MainPage::ShowHideControls(ViewMode mode)
auto isCalcViewMode = NavCategory::IsCalculatorViewMode(mode);
auto isDateCalcViewMode = NavCategory::IsDateCalculatorViewMode(mode);
auto isConverterViewMode = NavCategory::IsConverterViewMode(mode);
-
+
if (m_calculator)
{
m_calculator->Visibility = BooleanToVisibilityConverter::Convert(isCalcViewMode);
@@ -246,14 +242,9 @@ void MainPage::OnPageLoaded(_In_ Object^, _In_ RoutedEventArgs^ args)
m_model->CalculatorViewModel->IsStandard = true;
}
- _windowSizeEventToken = Window::Current->SizeChanged += ref new WindowSizeChangedEventHandler(this, &MainPage::WindowSizeChanged);
+ m_windowSizeEventToken = Window::Current->SizeChanged += ref new WindowSizeChangedEventHandler(this, &MainPage::WindowSizeChanged);
UpdateViewState();
- // Set custom XAML Title Bar window caption control button brushes
- m_uiSettings->ColorValuesChanged -= m_colorValuesChangedToken;
- m_colorValuesChangedToken = m_uiSettings->ColorValuesChanged += ref new TypedEventHandler(this, &MainPage::ColorValuesChanged);
- SetTitleBarControlColors();
-
SetHeaderAutomationName();
SetDefaultFocus();
@@ -269,12 +260,6 @@ void MainPage::OnPageLoaded(_In_ Object^, _In_ RoutedEventArgs^ args)
}));
}
-void MainPage::OnPageUnLoaded(_In_ Object^, _In_ RoutedEventArgs^)
-{
- // OnPageUnloaded Event Handler does not get fired when the calc window is closed.
- // On closing the instance of a window, On Window Consolidate gets fired.
-}
-
void MainPage::SetDefaultFocus()
{
if (m_calculator != nullptr && m_calculator->Visibility == ::Visibility::Visible)
@@ -310,9 +295,6 @@ void MainPage::EnsureCalculator()
m_calculator->SetBinding(m_calculator->IsProgrammerProperty, isProgramerBinding);
m_calculator->Style = CalculatorBaseStyle;
- m_fullscreenFlyoutClosedToken =
- m_calculator->FullscreenFlyoutClosed += ref new FullscreenFlyoutClosedEventHandler(this, &MainPage::OnFullscreenFlyoutClosed);
-
CalcHolder->Child = m_calculator;
// Calculator's "default" state is visible, but if we get delay loaded
@@ -493,62 +475,15 @@ void MainPage::ShowAboutPage()
FlyoutBase::ShowAttachedFlyout(AboutButton);
}
-void MainPage::ColorValuesChanged(_In_ UISettings^ sender, _In_ Object^ e)
-{
- WeakReference weakThis(this);
- RunOnUIThreadNonblocking([weakThis]()
- {
- auto refThis = weakThis.Resolve();
- if (refThis != nullptr)
- {
- refThis->SetTitleBarControlColors();
- }
- }, this->Dispatcher);
-}
-
-void MainPage::SetTitleBarControlColors()
-{
- auto applicationView = ApplicationView::GetForCurrentView();
- if (applicationView == nullptr) { return; }
-
- auto applicationTitleBar = applicationView->TitleBar;
- if (applicationTitleBar == nullptr) { return; }
-
- auto bgbrush = safe_cast(Application::Current->Resources->Lookup("SystemControlBackgroundTransparentBrush"));
- auto fgbrush = safe_cast(Application::Current->Resources->Lookup("SystemControlPageTextBaseHighBrush"));
- auto inactivefgbrush = safe_cast(Application::Current->Resources->Lookup("SystemControlForegroundChromeDisabledLowBrush"));
- auto hoverbgbrush = safe_cast(Application::Current->Resources->Lookup("SystemControlBackgroundListLowBrush"));
- auto hoverfgbrush = safe_cast(Application::Current->Resources->Lookup("SystemControlForegroundBaseHighBrush"));
- auto pressedbgbrush = safe_cast(Application::Current->Resources->Lookup("SystemControlBackgroundListMediumBrush"));
- auto pressedfgbrush = safe_cast(Application::Current->Resources->Lookup("SystemControlForegroundBaseHighBrush"));
-
- applicationTitleBar->ButtonBackgroundColor = bgbrush->Color;
- applicationTitleBar->ButtonForegroundColor = fgbrush->Color;
- applicationTitleBar->ButtonInactiveBackgroundColor = bgbrush->Color;
- applicationTitleBar->ButtonInactiveForegroundColor = inactivefgbrush->Color;
- applicationTitleBar->ButtonHoverBackgroundColor = hoverbgbrush->Color;
- applicationTitleBar->ButtonHoverForegroundColor = hoverfgbrush->Color;
- applicationTitleBar->ButtonPressedBackgroundColor = pressedbgbrush->Color;
- applicationTitleBar->ButtonPressedForegroundColor = pressedfgbrush->Color;
-}
-
void MainPage::UnregisterEventHandlers()
{
- m_uiSettings->ColorValuesChanged -= m_colorValuesChangedToken;
- m_colorValuesChangedToken.Value = 0;
-
- Window::Current->SizeChanged -= _windowSizeEventToken;
- _windowSizeEventToken.Value = 0;
+ Window::Current->SizeChanged -= m_windowSizeEventToken;
+ m_windowSizeEventToken.Value = 0;
if (m_calculator != nullptr)
{
- m_calculator->FullscreenFlyoutClosed -= m_fullscreenFlyoutClosedToken;
- m_fullscreenFlyoutClosedToken.Value = 0;
-
m_calculator->UnregisterEventHandlers();
}
-
- m_titleBarHelper = nullptr;
}
void MainPage::SetHeaderAutomationName()
@@ -572,7 +507,7 @@ void MainPage::SetHeaderAutomationName()
{
full = resProvider.GetResourceString(L"HeaderAutomationName_Converter")->Data();
}
-
+
string::size_type found = full.find(L"%1");
wstring strMode = m_model->CategoryName->Data();
full = full.replace(found, 2, strMode);
@@ -583,11 +518,6 @@ void MainPage::SetHeaderAutomationName()
AutomationProperties::SetName(Header, name);
}
-void MainPage::OnFullscreenFlyoutClosed()
-{
- this->CustomTitleBar->SetTitleBar();
-}
-
void MainPage::AnnounceCategoryName()
{
String^ categoryName = AutomationProperties::GetName(Header);
diff --git a/src/Calculator/Views/MainPage.xaml.h b/src/Calculator/Views/MainPage.xaml.h
index c80f5f8d..f95da83e 100644
--- a/src/Calculator/Views/MainPage.xaml.h
+++ b/src/Calculator/Views/MainPage.xaml.h
@@ -8,7 +8,6 @@
#include "Views/DateCalculator.xaml.h"
#include "Views/UnitConverter.xaml.h"
#include "CalcViewModel/ApplicationViewModel.h"
-#include "Views/TitleBar.xaml.h"
namespace CalculatorApp
{
@@ -44,8 +43,6 @@ namespace CalculatorApp
private:
void WindowSizeChanged(_In_ Platform::Object^ sender, _In_ Windows::UI::Core::WindowSizeChangedEventArgs^ e);
void OnAppPropertyChanged(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e);
- void SetTitleBarControlColors();
- void ColorValuesChanged(_In_ Windows::UI::ViewManagement::UISettings^ sender, _In_ Platform::Object^ e);
void OnNavLoaded(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void OnNavPaneOpening(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Platform::Object^ args);
@@ -59,16 +56,12 @@ namespace CalculatorApp
Microsoft::UI::Xaml::Controls::NavigationViewItemHeader^ CreateNavViewHeaderFromGroup(CalculatorApp::Common::NavCategoryGroup^ group);
Microsoft::UI::Xaml::Controls::NavigationViewItem^ CreateNavViewItemFromCategory(CalculatorApp::Common::NavCategory^ category);
-
- Windows::Foundation::EventRegistrationToken m_fullscreenFlyoutClosedToken;
- void OnFullscreenFlyoutClosed();
-
+
void ShowHideControls(CalculatorApp::Common::ViewMode mode);
void UpdateViewState();
void UpdatePanelViewState();
void OnPageLoaded(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
- void OnPageUnLoaded(_In_ Platform::Object^, _In_ Windows::UI::Xaml::RoutedEventArgs^);
void EnsureCalculator();
void EnsureConverter();
@@ -80,12 +73,7 @@ namespace CalculatorApp
CalculatorApp::Calculator^ m_calculator;
CalculatorApp::UnitConverter^ m_converter;
CalculatorApp::DateCalculator^ m_dateCalculator;
- Windows::Foundation::EventRegistrationToken _windowSizeEventToken;
- Windows::Foundation::EventRegistrationToken m_hardwareButtonsBackPressedToken;
- Windows::Foundation::EventRegistrationToken m_colorValuesChangedToken;
+ Windows::Foundation::EventRegistrationToken m_windowSizeEventToken;
CalculatorApp::ViewModel::ApplicationViewModel^ m_model;
- Windows::UI::ViewManagement::UISettings^ m_uiSettings;
-
- std::unique_ptr m_titleBarHelper;
};
}
diff --git a/src/Calculator/Views/Memory.xaml b/src/Calculator/Views/Memory.xaml
index 50db4050..d5f7d117 100644
--- a/src/Calculator/Views/Memory.xaml
+++ b/src/Calculator/Views/Memory.xaml
@@ -10,8 +10,6 @@
xmlns:model="using:CalculatorApp.ViewModel"
x:Name="MemoryList"
FlowDirection="LeftToRight"
- Loaded="MemoryList_Loaded"
- Unloaded="MemoryList_Unloaded"
mc:Ignorable="d">
@@ -49,7 +47,6 @@
-
@@ -69,11 +66,10 @@
-
+
-
-
+
@@ -84,7 +80,7 @@
-
+
@@ -135,9 +131,5 @@
Visibility="{x:Bind Model.IsMemoryEmpty, Mode=OneWay, Converter={StaticResource BooleanToVisibilityNegationConverter}}"/>
-
diff --git a/src/Calculator/Views/Memory.xaml.cpp b/src/Calculator/Views/Memory.xaml.cpp
index 7aa60118..aa047e22 100644
--- a/src/Calculator/Views/Memory.xaml.cpp
+++ b/src/Calculator/Views/Memory.xaml.cpp
@@ -120,19 +120,6 @@ void Memory::IsErrorVisualState::set(bool value)
}
}
-void Memory::MemoryList_Loaded(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
-{
- // When transitioning between docked and undocked view states, the memory list is
- // unloaded and then loaded, so we attempt to create the titlebarhelper every time
- // we are loaded, letting the util function check if we are docked or not.
- m_titleBarHelper = TitleBarHelper::CreateTitleBarHelperIfNotDocked(CustomTitleBar);
-}
-
-void Memory::MemoryList_Unloaded(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
-{
- m_titleBarHelper = nullptr;
-}
-
MemoryItemViewModel^ Memory::GetMemoryItemForCurrentFlyout()
{
auto listViewItem = m_memoryItemFlyout->Target;
diff --git a/src/Calculator/Views/Memory.xaml.h b/src/Calculator/Views/Memory.xaml.h
index 7a3e2da5..df5abe67 100644
--- a/src/Calculator/Views/Memory.xaml.h
+++ b/src/Calculator/Views/Memory.xaml.h
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
@@ -9,7 +9,6 @@
#pragma once
#include "Views/Memory.g.h"
-#include "Common/TitleBarHelper.h"
#include "Converters/BooleanNegationConverter.h"
#include "Converters/VisibilityNegationConverter.h"
#include "CalcViewModel/StandardCalculatorViewModel.h"
@@ -48,11 +47,8 @@ namespace CalculatorApp
void OnClearMenuItemClicked(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void OnMemoryAddMenuItemClicked(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void OnMemorySubtractMenuItemClicked(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
- void MemoryList_Loaded(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
- void MemoryList_Unloaded(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
CalculatorApp::ViewModel::MemoryItemViewModel^ GetMemoryItemForCurrentFlyout();
- std::unique_ptr m_titleBarHelper;
};
}
diff --git a/src/Calculator/Views/TitleBar.xaml b/src/Calculator/Views/TitleBar.xaml
index a42e2007..075540a7 100644
--- a/src/Calculator/Views/TitleBar.xaml
+++ b/src/Calculator/Views/TitleBar.xaml
@@ -4,12 +4,19 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
-
+ HorizontalAlignment="Stretch">
+
+
+
+
+
+
+
+
+
+
TitleBar)
{
+ m_uiSettings = ref new UISettings();
+ m_accessibilitySettings = ref new AccessibilitySettings();
InitializeComponent();
-
+
Loaded += ref new RoutedEventHandler(this, &TitleBar::OnLoaded);
Unloaded += ref new RoutedEventHandler(this, &TitleBar::OnUnloaded);
- m_coreTitleBar->ExtendViewIntoTitleBar = true;
-
- this->Initialize();
+ AppName->Text = AppResourceProvider::GetInstance().GetResourceString(L"AppName");
}
- void TitleBar::OnLoaded(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
+ void TitleBar::OnLoaded(_In_ Object^ /*sender*/, _In_ RoutedEventArgs^ /*e*/)
{
- this->RegisterForLayoutChanged();
- this->RegisterForVisibilityChanged();
- }
+ //Register events
+ m_visibilityChangedToken = m_coreTitleBar->IsVisibleChanged += ref new TypedEventHandler([this](CoreApplicationViewTitleBar^ cTitleBar, Object^)
+ {
+ this->SetTitleBarVisibility();
+ });
+ m_layoutChangedToken = m_coreTitleBar->LayoutMetricsChanged += ref new TypedEventHandler(
+ [this](CoreApplicationViewTitleBar^ cTitleBar, Object^)
+ {
+ this->LayoutRoot->Height = cTitleBar->Height;
+ this->SetTitleBarPadding();
+ });
- void TitleBar::OnUnloaded(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
- {
- m_coreTitleBar->LayoutMetricsChanged -= m_layoutChangedToken;
- m_coreTitleBar->IsVisibleChanged -= m_visibilityChangedToken;
- }
-
- void TitleBar::Initialize()
- {
- SetTitleBarText(AppResourceProvider::GetInstance().GetResourceString(L"AppName"));
- SetTitleBarHeight(m_coreTitleBar->Height);
- SetTitleBarVisibility(m_coreTitleBar->IsVisible);
+ m_colorValuesChangedToken = m_uiSettings->ColorValuesChanged += ref new TypedEventHandler(this, &TitleBar::ColorValuesChanged);
+ m_accessibilitySettingsToken = m_accessibilitySettings->HighContrastChanged += ref new Windows::Foundation::TypedEventHandler(this, &CalculatorApp::TitleBar::OnHighContrastChanged);
+ m_windowActivatedToken = Window::Current->Activated += ref new Windows::UI::Xaml::WindowActivatedEventHandler(this, &CalculatorApp::TitleBar::OnWindowActivated);
+ //Set properties
+ LayoutRoot->Height = m_coreTitleBar->Height;
+ SetTitleBarControlColors();
+ SetTitleBarExtendView();
+ SetTitleBarVisibility();
SetTitleBarPadding();
- SetTitleBar();
}
- void TitleBar::RegisterForLayoutChanged()
+ void TitleBar::OnUnloaded(_In_ Object^ /*sender*/, _In_ RoutedEventArgs^ /*e*/)
{
- m_layoutChangedToken =
- m_coreTitleBar->LayoutMetricsChanged += ref new TypedEventHandler(
- [this](CoreApplicationViewTitleBar^ cTitleBar, Object^)
- {
- // Update title bar control size as needed to account for system size changes
- SetTitleBarHeight(cTitleBar->Height);
- SetTitleBarPadding();
- });
+ //Unregister events
+ m_coreTitleBar->LayoutMetricsChanged -= m_layoutChangedToken;
+ m_layoutChangedToken.Value = 0;
+ m_coreTitleBar->IsVisibleChanged -= m_visibilityChangedToken;
+ m_visibilityChangedToken.Value = 0;
+ m_uiSettings->ColorValuesChanged -= m_colorValuesChangedToken;
+ m_colorValuesChangedToken.Value = 0;
+ m_accessibilitySettings->HighContrastChanged -= m_accessibilitySettingsToken;
+ m_accessibilitySettingsToken.Value = 0;
+ Window::Current->Activated -= m_windowActivatedToken;
+ m_windowActivatedToken.Value = 0;
}
- void TitleBar::RegisterForVisibilityChanged()
+ void TitleBar::SetTitleBarExtendView()
{
- m_visibilityChangedToken =
- m_coreTitleBar->IsVisibleChanged += ref new TypedEventHandler(
- [this](CoreApplicationViewTitleBar^ cTitleBar, Object^)
- {
- // Update title bar visibility
- SetTitleBarVisibility(cTitleBar->IsVisible);
- });
+ m_coreTitleBar->ExtendViewIntoTitleBar = !m_accessibilitySettings->HighContrast;
}
- void TitleBar::SetTitleBarText(String^ text)
+ void TitleBar::SetTitleBarVisibility()
{
- this->AppName->Text = text;
- }
-
- void TitleBar::SetTitleBarHeight(double height)
- {
- this->Height = height;
- }
-
- void TitleBar::SetTitleBarVisibility(bool isVisible)
- {
- this->Visibility = isVisible ? ::Visibility::Visible : ::Visibility::Collapsed;
+ this->LayoutRoot->Visibility = m_coreTitleBar->IsVisible && !m_accessibilitySettings->HighContrast ? ::Visibility::Visible : ::Visibility::Collapsed;
}
void TitleBar::SetTitleBarPadding()
@@ -103,14 +99,67 @@ namespace CalculatorApp
rightAddition = m_coreTitleBar->SystemOverlayLeftInset;
}
- auto padding = Thickness(leftAddition, 0, rightAddition, 0);
-
- this->LayoutRoot->Margin = padding;
+ this->LayoutRoot->Padding = Thickness(leftAddition, 0, rightAddition, 0);
}
- void TitleBar::SetTitleBar()
+ void TitleBar::ColorValuesChanged(_In_ UISettings^ /*sender*/, _In_ Object^ /*e*/)
{
- Window::Current->SetTitleBar(this->LayoutRoot);
+ Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]() {
+ SetTitleBarControlColors();
+ }));
+ }
+
+ void TitleBar::SetTitleBarControlColors()
+ {
+ auto applicationView = ApplicationView::GetForCurrentView();
+ if (applicationView == nullptr) { return; }
+
+ auto applicationTitleBar = applicationView->TitleBar;
+ if (applicationTitleBar == nullptr) { return; }
+
+ if (m_accessibilitySettings->HighContrast)
+ {
+ //Reset to use default colors.
+ applicationTitleBar->ButtonBackgroundColor = nullptr;
+ applicationTitleBar->ButtonForegroundColor = nullptr;
+ applicationTitleBar->ButtonInactiveBackgroundColor = nullptr;
+ applicationTitleBar->ButtonInactiveForegroundColor = nullptr;
+ applicationTitleBar->ButtonHoverBackgroundColor = nullptr;
+ applicationTitleBar->ButtonHoverForegroundColor = nullptr;
+ applicationTitleBar->ButtonPressedBackgroundColor = nullptr;
+ applicationTitleBar->ButtonPressedForegroundColor = nullptr;
+ }
+ else
+ {
+ Color bgColor = Colors::Transparent;
+ Color fgColor = safe_cast(Application::Current->Resources->Lookup("SystemControlPageTextBaseHighBrush"))->Color;
+ Color inactivefgColor = safe_cast(Application::Current->Resources->Lookup("SystemControlForegroundChromeDisabledLowBrush"))->Color;
+ Color hoverbgColor = safe_cast(Application::Current->Resources->Lookup("SystemControlBackgroundListLowBrush"))->Color;
+ Color hoverfgColor = safe_cast(Application::Current->Resources->Lookup("SystemControlForegroundBaseHighBrush"))->Color;
+ Color pressedbgColor = safe_cast(Application::Current->Resources->Lookup("SystemControlBackgroundListMediumBrush"))->Color;
+ Color pressedfgCoolor = safe_cast(Application::Current->Resources->Lookup("SystemControlForegroundBaseHighBrush"))->Color;
+ applicationTitleBar->ButtonBackgroundColor = bgColor;
+ applicationTitleBar->ButtonForegroundColor = fgColor;
+ applicationTitleBar->ButtonInactiveBackgroundColor = bgColor;
+ applicationTitleBar->ButtonInactiveForegroundColor = inactivefgColor;
+ applicationTitleBar->ButtonHoverBackgroundColor = hoverbgColor;
+ applicationTitleBar->ButtonHoverForegroundColor = hoverfgColor;
+ applicationTitleBar->ButtonPressedBackgroundColor = pressedbgColor;
+ applicationTitleBar->ButtonPressedForegroundColor = pressedfgCoolor;
+ }
+ }
+
+ void TitleBar::OnHighContrastChanged(_In_ AccessibilitySettings ^ /*sender*/, _In_ Object ^ /*args*/)
+ {
+ Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]() {
+ SetTitleBarControlColors();
+ SetTitleBarExtendView();
+ SetTitleBarVisibility();
+ }));
+ }
+
+ void TitleBar::OnWindowActivated(_In_ Object ^ /*sender*/, _In_ WindowActivatedEventArgs ^e)
+ {
+ VisualStateManager::GoToState(this, e->WindowActivationState == CoreWindowActivationState::Deactivated ? WindowNotFocused->Name : WindowFocused->Name, false);
}
}
-
diff --git a/src/Calculator/Views/TitleBar.xaml.h b/src/Calculator/Views/TitleBar.xaml.h
index 85a360b7..f1cdf831 100644
--- a/src/Calculator/Views/TitleBar.xaml.h
+++ b/src/Calculator/Views/TitleBar.xaml.h
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
@@ -7,26 +7,36 @@
namespace CalculatorApp
{
+
+ ///
+ /// Standalone control managing the title bar of the application.
+ /// Display a transparent custom title bar when high-contrast is off and the native title bar when on.
+ /// Automatically react to color changes, tablet mode, etc...
+ ///
public ref class TitleBar sealed
{
public:
TitleBar();
-
- void SetTitleBar();
private:
void OnLoaded(_In_ Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnUnloaded(_In_ Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
- void Initialize();
- void RegisterForLayoutChanged();
- void RegisterForVisibilityChanged();
void SetTitleBarText(Platform::String^ text);
- void SetTitleBarHeight(double height);
- void SetTitleBarVisibility(bool isVisible);
+ void SetTitleBarVisibility();
void SetTitleBarPadding();
+ void SetTitleBarControlColors();
+ void SetTitleBarExtendView();
+ void ColorValuesChanged(_In_ Windows::UI::ViewManagement::UISettings^ sender, _In_ Platform::Object^ e);
+ void OnHighContrastChanged(Windows::UI::ViewManagement::AccessibilitySettings ^sender, Platform::Object ^args);
+ void OnWindowActivated(Platform::Object ^sender, Windows::UI::Core::WindowActivatedEventArgs ^e);
Platform::Agile m_coreTitleBar;
Windows::Foundation::EventRegistrationToken m_layoutChangedToken;
Windows::Foundation::EventRegistrationToken m_visibilityChangedToken;
+ Windows::Foundation::EventRegistrationToken m_colorValuesChangedToken;
+ Windows::Foundation::EventRegistrationToken m_windowActivatedToken;
+ Windows::Foundation::EventRegistrationToken m_accessibilitySettingsToken;
+ Windows::UI::ViewManagement::UISettings^ m_uiSettings;
+ Windows::UI::ViewManagement::AccessibilitySettings^ m_accessibilitySettings;
};
}