Fixes #407 (partially) and #441

Description of the changes:
Remove TitleBarHelper and all <Border x:Name="CustomTitleBar" />
Let the system defines the draggable region
Centralize all events and functions associated to the title bar in a single control TitleBar instead of code splitted between MainPage/TitleBar/HistoryList/Memory.
Use the standard title bar when high contrast is activated instead of the custom one.
Modify the color of the title when the window doesn't have focus
Fix the right padding of the title bar with high contrast

How changes were validated:
Manually tested with LtR and RtL languages
Manually tested with high contrast
Tested when History and Memory flyout are opened
This commit is contained in:
Rudy Huyn 2019-04-19 18:49:08 -07:00 коммит произвёл Daniel Belcher
Родитель 0d31d5a5a2
Коммит bd04c92c1c
19 изменённых файлов: 168 добавлений и 394 удалений

Просмотреть файл

@ -19,7 +19,6 @@
<Color x:Key="ChromeMediumLowColor">#FF2B2B2B</Color>
<SolidColorBrush x:Key="SystemControlBackgroundAltHighBrush" Color="{StaticResource AltHighColor}"/>
<SolidColorBrush x:Key="SystemControlBackgroundChromeMediumLowBrush" Color="{StaticResource ChromeMediumLowColor}"/>
<SolidColorBrush x:Key="TitleBarBackgroundTransparentBrush" Color="Transparent"/>
<SolidColorBrush x:Key="TitleBarForegroundBaseHighBrush" Color="{StaticResource SystemBaseHighColor}"/>
<SolidColorBrush x:Key="SystemControlBackgroundTransparentBrush" Color="Transparent"/>
<SolidColorBrush x:Key="SystemControlHighlightTransparentBrush" Color="Transparent"/>
@ -55,7 +54,6 @@
<Color x:Key="ChromeMediumLowColor">#FFE0E0E0</Color>
<SolidColorBrush x:Key="SystemControlBackgroundAltHighBrush" Color="{StaticResource SystemAltHighColor}"/>
<SolidColorBrush x:Key="SystemControlBackgroundChromeMediumLowBrush" Color="{StaticResource ChromeMediumLowColor}"/>
<SolidColorBrush x:Key="TitleBarBackgroundTransparentBrush" Color="Transparent"/>
<SolidColorBrush x:Key="TitleBarForegroundBaseHighBrush" Color="{StaticResource SystemBaseHighColor}"/>
<SolidColorBrush x:Key="SystemControlBackgroundTransparentBrush" Color="Transparent"/>
<SolidColorBrush x:Key="SystemControlHighlightTransparentBrush" Color="Transparent"/>
@ -89,7 +87,6 @@
<x:Double x:Key="HighContrastStrokeThickness">2</x:Double>
<SolidColorBrush x:Key="SystemControlBackgroundAltHighBrush" Color="{ThemeResource SystemColorButtonFaceColor}"/>
<SolidColorBrush x:Key="SystemControlBackgroundChromeMediumLowBrush" Color="{ThemeResource SystemColorButtonFaceColor}"/>
<SolidColorBrush x:Key="TitleBarBackgroundTransparentBrush" Color="{ThemeResource SystemColorActiveCaptionColor}"/>
<SolidColorBrush x:Key="TitleBarForegroundBaseHighBrush" Color="{ThemeResource SystemColorCaptionTextColor}"/>
<SolidColorBrush x:Key="SystemControlBackgroundTransparentBrush" Color="{ThemeResource SystemColorButtonFaceColor}"/>
<SolidColorBrush x:Key="SystemControlHighlightTransparentBrush" Color="{ThemeResource SystemColorHighlightColor}"/>

Просмотреть файл

@ -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;

Просмотреть файл

@ -252,7 +252,6 @@
<ClInclude Include="App.xaml.h">
<DependentUpon>App.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="Common\TitleBarHelper.h" />
<ClInclude Include="Views\Calculator.xaml.h">
<DependentUpon>Views\Calculator.xaml</DependentUpon>
</ClInclude>
@ -389,7 +388,6 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="Common\TitleBarHelper.cpp" />
<ClCompile Include="Views\Calculator.xaml.cpp">
<DependentUpon>Views\Calculator.xaml</DependentUpon>
</ClCompile>

Просмотреть файл

@ -278,9 +278,6 @@
</ClCompile>
<ClCompile Include="WindowFrameService.cpp" />
<ClCompile Include="Views\DateCalculator.xaml.cpp" />
<ClCompile Include="Common\TitleBarHelper.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Controls\CalculationResultAutomationPeer.cpp">
<Filter>Controls</Filter>
</ClCompile>
@ -290,7 +287,6 @@
<ClCompile Include="Views\StateTriggers\AspectRatioTrigger.cpp">
<Filter>Views\StateTriggers</Filter>
</ClCompile>
<ClCompile Include="Views\TitleBar.xaml.cpp" />
<ClCompile Include="Views\MemoryListItem.xaml.cpp" />
<ClCompile Include="Views\OperatorsPanel.xaml.cpp" />
<ClCompile Include="Controls\SupplementaryItemsControl.cpp">
@ -302,6 +298,7 @@
<ClCompile Include="Controls\HorizontalNoOverflowStackPanel.cpp">
<Filter>Controls</Filter>
</ClCompile>
<ClCompile Include="Views\TitleBar.xaml.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
@ -368,9 +365,6 @@
<ClInclude Include="Converters\BitFlipAutomationNameConverter.h">
<Filter>Converters</Filter>
</ClInclude>
<ClInclude Include="Common\TitleBarHelper.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Controls\CalculationResultAutomationPeer.h">
<Filter>Controls</Filter>
</ClInclude>
@ -380,7 +374,6 @@
<ClInclude Include="Views\StateTriggers\AspectRatioTrigger.h">
<Filter>Views\StateTriggers</Filter>
</ClInclude>
<ClInclude Include="Views\TitleBar.xaml.h" />
<ClInclude Include="Views\MemoryListItem.xaml.h" />
<ClInclude Include="Views\OperatorsPanel.xaml.h" />
<ClInclude Include="Controls\SupplementaryItemsControl.h">
@ -392,6 +385,7 @@
<ClInclude Include="Controls\HorizontalNoOverflowStackPanel.h">
<Filter>Controls</Filter>
</ClInclude>
<ClInclude Include="Views\TitleBar.xaml.h" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest" />
@ -450,15 +444,15 @@
<Page Include="Views\DateCalculator.xaml">
<Filter>Views</Filter>
</Page>
<Page Include="Views\TitleBar.xaml">
<Filter>Views</Filter>
</Page>
<Page Include="Views\MemoryListItem.xaml">
<Filter>Views</Filter>
</Page>
<Page Include="Views\OperatorsPanel.xaml">
<Filter>Views</Filter>
</Page>
<Page Include="Views\TitleBar.xaml">
<Filter>Views</Filter>
</Page>
</ItemGroup>
<ItemGroup>
<PRIResource Include="Resources\en-US\CEngineStrings.resw">

Просмотреть файл

@ -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> TitleBarHelper::CreateTitleBarHelperIfNotDocked(FrameworkElement^ customTitleBar)
{
return (App::GetAppViewState() == ViewState::DockedView)
? nullptr
: CalculatorApp::Common::TitleBarHelper::CreateTitleBarHelper(customTitleBar);
}
unique_ptr<TitleBarHelper> 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<TitleBarHelper>(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<CoreApplicationViewTitleBar^, Object^>(
[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<CoreApplicationViewTitleBar^, Object^>(
[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);
}

Просмотреть файл

@ -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<TitleBarHelper> CreateTitleBarHelperIfNotDocked(
_In_ Windows::UI::Xaml::FrameworkElement^ customTitleBar);
// Prefer CreateTitleBarHelper over constructing your own instance,
// because Create* will nullcheck the parameters.
static std::unique_ptr<TitleBarHelper> 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<Windows::ApplicationModel::Core::CoreApplicationViewTitleBar^> m_coreTitleBar;
Windows::UI::Xaml::FrameworkElement^ m_customTitleBar;
Windows::Foundation::EventRegistrationToken m_layoutChangedToken;
Windows::Foundation::EventRegistrationToken m_visibilityChangedToken;
};
}
}

Просмотреть файл

@ -172,11 +172,6 @@
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTransitions="{TemplateBinding ContentTransitions}"/>
<Border x:Name="CustomTitleBar"
Height="32"
HorizontalAlignment="Stretch"
Background="{ThemeResource TitleBarBackgroundTransparentBrush}"/>
</Grid>
</ControlTemplate>
</Setter.Value>

Просмотреть файл

@ -12,8 +12,6 @@
x:Name="HistoryList"
AutomationProperties.AutomationId="HistoryList"
FlowDirection="LeftToRight"
Loaded="HistoryList_Loaded"
Unloaded="HistoryList_Unloaded"
mc:Ignorable="d">
<UserControl.Resources>
@ -93,7 +91,6 @@
<Grid x:Name="LayoutGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="{Binding RowHeight, ElementName=HistoryList, Mode=OneWay}"/>
</Grid.RowDefinitions>
@ -105,11 +102,10 @@
<AdaptiveTrigger MinWindowWidth="560"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="HistoryListRootGrid.(Grid.Row)" Value="1"/>
<Setter Target="HistoryListRootGrid.(Grid.Row)" Value="0"/>
<Setter Target="HistoryListRootGrid.(Grid.RowSpan)" Value="2"/>
<Setter Target="HistoryListView.Padding" Value="0"/>
<Setter Target="BackgroundShade.Opacity" Value="0"/>
<Setter Target="CustomTitleBar.Height" Value="0"/>
<Setter Target="BackgroundShade.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="DefaultLayout">
@ -120,7 +116,7 @@
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="BackgroundShade"
Grid.Row="2"
Grid.Row="1"
Margin="0,-1,0,0"
Padding="0"
HorizontalAlignment="Stretch"
@ -129,7 +125,7 @@
BorderBrush="{ThemeResource SystemControlForegroundChromeHighBrush}"
BorderThickness="{ThemeResource HighContrastThicknessTop}"/>
<Grid x:Name="HistoryListRootGrid" Grid.Row="2">
<Grid x:Name="HistoryListRootGrid" Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
@ -171,10 +167,5 @@
Content="&#xE74D;"
Visibility="{x:Bind Model.ItemSize, Mode=OneWay, Converter={StaticResource ItemSizeToVisibilityNegationConverter}}"/>
</Grid>
<Border x:Name="CustomTitleBar"
Height="32"
HorizontalAlignment="Stretch"
Background="{ThemeResource TitleBarBackgroundTransparentBrush}"/>
</Grid>
</UserControl>

Просмотреть файл

@ -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<HistoryViewModel^>(this->DataContext);

Просмотреть файл

@ -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<CalculatorApp::Common::TitleBarHelper> m_titleBarHelper;
};
}

Просмотреть файл

@ -13,7 +13,6 @@
x:Name="PageRoot"
Background="{ThemeResource AppChromeAcrylicHostBackdropMediumLowBrush}"
Loaded="OnPageLoaded"
Unloaded="OnPageUnLoaded"
mc:Ignorable="d">
<Page.Resources>
@ -38,11 +37,6 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<!--
This row is padding for the SystemFocusVisuals,
otherwise the focus rectangles render under the title bar controls.
-->
<RowDefinition x:Name="FocusVisualMargin" Height="3"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
@ -89,14 +83,11 @@
Command="{x:Bind Model.PasteCommand}"/>
</StackPanel>
<!-- Title Bar -->
<local:TitleBar x:Name="CustomTitleBar"
Grid.Row="0"
Visibility="Collapsed"/>
<local:TitleBar x:Name="CustomTitleBar" Grid.Row="0"/>
<muxc:NavigationView x:Name="NavView"
x:Uid="NavView"
Grid.Row="2"
Grid.Row="1"
CompactModeThresholdWidth="Infinity"
DataContext="{x:Bind Model}"
ExpandedModeThresholdWidth="Infinity"

Просмотреть файл

@ -11,7 +11,6 @@
#include "Views/Memory.xaml.h"
#include "Converters/BooleanToVisibilityConverter.h"
#include "Common/AppLifecycleLogger.h"
using namespace CalculatorApp;
using namespace CalculatorApp::Common;
using namespace CalculatorApp::Common::Automation;
@ -69,8 +68,6 @@ MainPage::MainPage() :
{
InitializeComponent();
m_uiSettings = ref new UISettings();
KeyboardShortcutManager::Initialize();
m_model->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<UISettings^, Object^>(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<MainPage>();
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<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlBackgroundTransparentBrush"));
auto fgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlPageTextBaseHighBrush"));
auto inactivefgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlForegroundChromeDisabledLowBrush"));
auto hoverbgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlBackgroundListLowBrush"));
auto hoverfgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlForegroundBaseHighBrush"));
auto pressedbgbrush = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlBackgroundListMediumBrush"));
auto pressedfgbrush = safe_cast<SolidColorBrush^>(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);

Просмотреть файл

@ -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<CalculatorApp::Common::TitleBarHelper> m_titleBarHelper;
};
}

Просмотреть файл

@ -10,8 +10,6 @@
xmlns:model="using:CalculatorApp.ViewModel"
x:Name="MemoryList"
FlowDirection="LeftToRight"
Loaded="MemoryList_Loaded"
Unloaded="MemoryList_Unloaded"
mc:Ignorable="d">
<UserControl.Resources>
@ -49,7 +47,6 @@
<Grid x:Name="LayoutGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="{Binding RowHeight, ElementName=MemoryList, Mode=OneWay}"/>
</Grid.RowDefinitions>
@ -69,11 +66,10 @@
<AdaptiveTrigger MinWindowWidth="560"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="MemoryPanel.(Grid.Row)" Value="1"/>
<Setter Target="MemoryPanel.(Grid.Row)" Value="0"/>
<Setter Target="MemoryPanel.(Grid.RowSpan)" Value="2"/>
<Setter Target="MemoryListView.Padding" Value="0"/>
<Setter Target="BackgroundShade.Opacity" Value="0"/>
<Setter Target="CustomTitleBar.Height" Value="0"/>
<Setter Target="BackgroundShade.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="DefaultLayout">
@ -84,7 +80,7 @@
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="BackgroundShade"
Grid.Row="2"
Grid.Row="1"
Margin="0,-1,0,0"
Padding="0"
HorizontalAlignment="Stretch"
@ -92,7 +88,7 @@
Background="{ThemeResource SystemControlChromeMediumLowAcrylicElementMediumBrush}"
BorderBrush="{ThemeResource SystemControlForegroundChromeHighBrush}"
BorderThickness="{ThemeResource HighContrastThicknessTop}"/>
<Grid x:Name="MemoryPanel" Grid.Row="2">
<Grid x:Name="MemoryPanel" Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
@ -135,9 +131,5 @@
Visibility="{x:Bind Model.IsMemoryEmpty, Mode=OneWay, Converter={StaticResource BooleanToVisibilityNegationConverter}}"/>
</Grid>
<Border x:Name="CustomTitleBar"
Height="32"
HorizontalAlignment="Stretch"
Background="{ThemeResource TitleBarBackgroundTransparentBrush}"/>
</Grid>
</UserControl>

Просмотреть файл

@ -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;

Просмотреть файл

@ -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<CalculatorApp::Common::TitleBarHelper> m_titleBarHelper;
};
}

Просмотреть файл

@ -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">
<Grid x:Name="LayoutRoot"
Height="32"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Background="{ThemeResource TitleBarBackgroundTransparentBrush}">
HorizontalAlignment="Stretch">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="WindowFocusStates">
<VisualState x:Name="WindowFocused"/>
<VisualState x:Name="WindowNotFocused">
<VisualState.Setters>
<Setter Target="AppName.Foreground" Value="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<TextBlock x:Name="AppName"
x:Uid="AppName"
Margin="12,0,12,0"

Просмотреть файл

@ -1,16 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "pch.h"
#include "TitleBar.xaml.h"
#include "CalcViewModel/Common/AppResourceProvider.h"
#include "CalcViewModel/Common/Utils.h"
using namespace std;
using namespace Platform;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Foundation;
using namespace Windows::UI;
using namespace Windows::UI::Core;
using namespace Windows::UI::ViewManagement;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::Foundation::Collections;
namespace CalculatorApp
@ -18,73 +23,64 @@ namespace CalculatorApp
TitleBar::TitleBar() :
m_coreTitleBar(CoreApplication::GetCurrentView()->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<CoreApplicationViewTitleBar^, Object^>([this](CoreApplicationViewTitleBar^ cTitleBar, Object^)
{
this->SetTitleBarVisibility();
});
m_layoutChangedToken = m_coreTitleBar->LayoutMetricsChanged += ref new TypedEventHandler<CoreApplicationViewTitleBar^, Object^>(
[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<UISettings^, Object^>(this, &TitleBar::ColorValuesChanged);
m_accessibilitySettingsToken = m_accessibilitySettings->HighContrastChanged += ref new Windows::Foundation::TypedEventHandler<AccessibilitySettings ^, Object ^>(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<CoreApplicationViewTitleBar^, Object^>(
[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<CoreApplicationViewTitleBar^, Object^>(
[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<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlPageTextBaseHighBrush"))->Color;
Color inactivefgColor = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlForegroundChromeDisabledLowBrush"))->Color;
Color hoverbgColor = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlBackgroundListLowBrush"))->Color;
Color hoverfgColor = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlForegroundBaseHighBrush"))->Color;
Color pressedbgColor = safe_cast<SolidColorBrush^>(Application::Current->Resources->Lookup("SystemControlBackgroundListMediumBrush"))->Color;
Color pressedfgCoolor = safe_cast<SolidColorBrush^>(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);
}
}

Просмотреть файл

@ -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
{
/// <summary>
/// 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...
/// </summary>
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<Windows::ApplicationModel::Core::CoreApplicationViewTitleBar^> 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;
};
}