Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dev/TJ/KeyboardScroll…
Browse files Browse the repository at this point in the history
…ing-Improvements1
  • Loading branch information
tj-devel709 committed Sep 27, 2023
2 parents 6cc92b1 + 0a05525 commit 6abc38f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 14 deletions.
33 changes: 31 additions & 2 deletions src/Core/src/Platform/Windows/MauiWinUIWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
using System.Runtime.InteropServices;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Devices;
using Microsoft.Maui.LifecycleEvents;
using Microsoft.UI;
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Windows.Graphics;
using ViewManagement = Windows.UI.ViewManagement;

namespace Microsoft.Maui
{
Expand All @@ -21,10 +22,12 @@ public class MauiWinUIWindow : UI.Xaml.Window, IPlatformSizeRestrictedWindow
IntPtr _windowIcon;
bool _enableResumeEvent;
bool _isActivated;
ViewManagement.UISettings _viewSettings;

public MauiWinUIWindow()
{
_windowManager = WindowMessageManager.Get(this);
_viewSettings = new ViewManagement.UISettings();

Activated += OnActivated;
Closed += OnClosedPrivate;
Expand All @@ -34,7 +37,16 @@ public MauiWinUIWindow()
// set to false we know the user toggled this to false
// and then we can react accordingly
if (AppWindowTitleBar.IsCustomizationSupported())
{
base.AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
_viewSettings.ColorValuesChanged += _viewSettings_ColorValuesChanged;
SetTileBarButtonColors();
}

if (MicaController.IsSupported())
{
base.SystemBackdrop = new MicaBackdrop() { Kind = MicaKind.BaseAlt };
}

SubClassingWin32();
SetIcon();
Expand Down Expand Up @@ -69,6 +81,8 @@ private void OnClosedPrivate(object sender, UI.Xaml.WindowEventArgs args)
{
OnClosed(sender, args);

_viewSettings.ColorValuesChanged -= _viewSettings_ColorValuesChanged;

if (_windowIcon != IntPtr.Zero)
{
DestroyIcon(_windowIcon);
Expand Down Expand Up @@ -179,6 +193,21 @@ void SetIcon()
}
}

private void _viewSettings_ColorValuesChanged(ViewManagement.UISettings sender, object args)
{
DispatcherQueue.TryEnqueue(SetTileBarButtonColors);
}

private void SetTileBarButtonColors()
{
if (AppWindowTitleBar.IsCustomizationSupported())
{
base.AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
base.AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
base.AppWindow.TitleBar.ButtonForegroundColor = _viewSettings.GetColorValue(ViewManagement.UIColorType.Foreground);
}
}

SizeInt32 IPlatformSizeRestrictedWindow.MinimumSize { get; set; } = DefaultMinimumSize;

SizeInt32 IPlatformSizeRestrictedWindow.MaximumSize { get; set; } = DefaultMaximumSize;
Expand Down
10 changes: 0 additions & 10 deletions src/Core/src/Platform/Windows/Styles/WindowRootViewStyle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui.Platform">

<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="TitleBarBackgroundColor" Color="#FF000000" />
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="TitleBarBackgroundColor" Color="#FFFFFFFF" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>

<maui:DefaultOrUserDataTemplateSelector
UserTemplateName="MauiAppTitleBarTemplate"
DefaultTemplateName="MauiAppTitleBarTemplateDefault"
Expand All @@ -26,7 +17,6 @@
<Border
Canvas.ZIndex="1"
VerticalAlignment="Stretch"
Background="{ThemeResource TitleBarBackgroundColor}"
Margin="0,0,0,0">
<StackPanel Orientation="Horizontal" Margin="12, 0, 0, 0" x:Name="RootStackPanel">
<Image
Expand Down
39 changes: 37 additions & 2 deletions src/Core/src/Platform/Windows/WindowRootView.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media;
using Microsoft.Win32;
using Windows.Foundation;
using ViewManagement = Windows.UI.ViewManagement;
using WThickness = Microsoft.UI.Xaml.Thickness;

namespace Microsoft.Maui.Platform
Expand All @@ -23,11 +24,13 @@ public static readonly DependencyProperty AppTitleBarTemplateProperty
MenuBar? _menuBar;
FrameworkElement? _appTitleBar;
bool _hasTitleBarImage = false;
ViewManagement.UISettings _viewSettings;
public event TypedEventHandler<NavigationView, NavigationViewBackRequestedEventArgs>? BackRequested;

public WindowRootView()
{
IsTabStop = false;
_viewSettings = new ViewManagement.UISettings();
}

internal double AppTitleBarActualHeight => AppTitleBarContentControl?.ActualHeight ?? 0;
Expand Down Expand Up @@ -127,6 +130,8 @@ protected override void OnApplyTemplate()
{
base.OnApplyTemplate();

_viewSettings.ColorValuesChanged += ViewSettingsColorValuesChanged;

AppTitleBarContainer = (FrameworkElement)GetTemplateChild("AppTitleBarContainer");
AppTitleBarContentControl = (ContentControl?)GetTemplateChild("AppTitleBarContentControl") ??
AppTitleBarContainer.GetDescendantByName<ContentControl>("AppTitleBarContentControl");
Expand Down Expand Up @@ -182,6 +187,7 @@ void LoadAppTitleBarContainer()
}
};
}

void OnAppTitleBarContentControlLoaded(object sender, RoutedEventArgs e)
{
LoadAppTitleBarControls();
Expand Down Expand Up @@ -221,9 +227,38 @@ void LoadAppTitleBarControls()
AppFontIcon.ImageFailed += OnImageFailed;
}

ApplyTitlebarColorPrevalence();
UpdateAppTitleBarMargins();
}

private void ViewSettingsColorValuesChanged(ViewManagement.UISettings sender, object args)
{
ApplyTitlebarColorPrevalence();
}

void ApplyTitlebarColorPrevalence()
{
try
{
// Figure out if the "show accent color on title bars" setting is enabled
using var dwmSubKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\DWM\");
var enableAccentColor = dwmSubKey?.GetValue("ColorPrevalence");
if (enableAccentColor != null &&
int.TryParse(enableAccentColor.ToString(), out var enableValue) &&
_appTitleBar is Border border)
{
DispatcherQueue.TryEnqueue(() => {
border.Background = enableValue == 1 ?
new SolidColorBrush(_viewSettings.GetColorValue(ViewManagement.UIColorType.Accent)) :
new SolidColorBrush(UI.Colors.Transparent);

if (NavigationViewControl != null && NavigationViewControl.ButtonHolderGrid != null)
NavigationViewControl.ButtonHolderGrid.Background = border.Background;
});
}
}
catch (Exception) { }
}

ActionDisposable? _contentChanged;

Expand Down

0 comments on commit 6abc38f

Please sign in to comment.