Skip to content

Commit

Permalink
Update to Windows App SDK 1.4.230913002 & WinUIEx 2.3.2 (#4712)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysterious-Dev authored Nov 10, 2023
1 parent 4a8b81a commit 52d63a4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ts.outputToParent": "true",
"ts.version": "1.0.0",
"ts.displayOrder": "0",
"ts.licenses": "[Microsoft.WindowsAppSDK](https://www.nuget.org/packages/Microsoft.WindowsAppSDK/1.3.230331000/License)|[WinUIEx](https://licenses.nuget.org/MIT)"
"ts.licenses": "[Microsoft.WindowsAppSDK](https://www.nuget.org/packages/Microsoft.WindowsAppSDK/1.4.231008000/License)|[WinUIEx](https://licenses.nuget.org/MIT)"
},
"sourceName": "Param_ProjectName",
"preferNameDirectory": true,
Expand Down Expand Up @@ -87,7 +87,7 @@
"actionId": "0B814718-16A3-4F7F-89F1-69C0F9170EAD",
"args": {
"packageId": "Microsoft.WindowsAppSDK",
"version": "1.3.230502000",
"version": "1.4.231008000",
"projectPath": "Param_ProjectName\\Param_ProjectName.csproj"
},
"continueOnError": true
Expand All @@ -98,7 +98,7 @@
"actionId": "0B814718-16A3-4F7F-89F1-69C0F9170EAD",
"args": {
"packageId": "WinUIEx",
"version": "2.2",
"version": "2.3.2",
"projectPath": "Param_ProjectName\\Param_ProjectName.csproj"
},
"continueOnError": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,50 +39,35 @@ public static void UpdateTitleBar(ElementTheme theme)
theme = Application.Current.RequestedTheme == ApplicationTheme.Light ? ElementTheme.Light : ElementTheme.Dark;
}

Application.Current.Resources["WindowCaptionForeground"] = theme switch
App.MainWindow.AppWindow.TitleBar.ButtonForegroundColor = theme switch
{
ElementTheme.Dark => new SolidColorBrush(Colors.White),
ElementTheme.Light => new SolidColorBrush(Colors.Black),
_ => new SolidColorBrush(Colors.Transparent)
ElementTheme.Dark => Colors.White,
ElementTheme.Light => Colors.Black,
_ => Colors.Transparent
};

Application.Current.Resources["WindowCaptionForegroundDisabled"] = theme switch
App.MainWindow.AppWindow.TitleBar.ButtonHoverForegroundColor = theme switch
{
ElementTheme.Dark => new SolidColorBrush(Color.FromArgb(0x66, 0xFF, 0xFF, 0xFF)),
ElementTheme.Light => new SolidColorBrush(Color.FromArgb(0x66, 0x00, 0x00, 0x00)),
_ => new SolidColorBrush(Colors.Transparent)
ElementTheme.Dark => Colors.White,
ElementTheme.Light => Colors.Black,
_ => Colors.Transparent
};

Application.Current.Resources["WindowCaptionButtonBackgroundPointerOver"] = theme switch
App.MainWindow.AppWindow.TitleBar.ButtonHoverBackgroundColor = theme switch
{
ElementTheme.Dark => new SolidColorBrush(Color.FromArgb(0x33, 0xFF, 0xFF, 0xFF)),
ElementTheme.Light => new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00)),
_ => new SolidColorBrush(Colors.Transparent)
ElementTheme.Dark => Color.FromArgb(0x33, 0xFF, 0xFF, 0xFF),
ElementTheme.Light => Color.FromArgb(0x33, 0x00, 0x00, 0x00),
_ => Colors.Transparent
};

Application.Current.Resources["WindowCaptionButtonBackgroundPressed"] = theme switch
App.MainWindow.AppWindow.TitleBar.ButtonPressedBackgroundColor = theme switch
{
ElementTheme.Dark => new SolidColorBrush(Color.FromArgb(0x66, 0xFF, 0xFF, 0xFF)),
ElementTheme.Light => new SolidColorBrush(Color.FromArgb(0x66, 0x00, 0x00, 0x00)),
_ => new SolidColorBrush(Colors.Transparent)
ElementTheme.Dark => Color.FromArgb(0x66, 0xFF, 0xFF, 0xFF),
ElementTheme.Light => Color.FromArgb(0x66, 0x00, 0x00, 0x00),
_ => Colors.Transparent
};

Application.Current.Resources["WindowCaptionButtonStrokePointerOver"] = theme switch
{
ElementTheme.Dark => new SolidColorBrush(Colors.White),
ElementTheme.Light => new SolidColorBrush(Colors.Black),
_ => new SolidColorBrush(Colors.Transparent)
};

Application.Current.Resources["WindowCaptionButtonStrokePressed"] = theme switch
{
ElementTheme.Dark => new SolidColorBrush(Colors.White),
ElementTheme.Light => new SolidColorBrush(Colors.Black),
_ => new SolidColorBrush(Colors.Transparent)
};

Application.Current.Resources["WindowCaptionBackground"] = new SolidColorBrush(Colors.Transparent);
Application.Current.Resources["WindowCaptionBackgroundDisabled"] = new SolidColorBrush(Colors.Transparent);
App.MainWindow.AppWindow.TitleBar.BackgroundColor = Colors.Transparent;

var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(App.MainWindow);
if (hwnd == GetActiveWindow())
Expand All @@ -100,19 +85,9 @@ public static void UpdateTitleBar(ElementTheme theme)

public static void ApplySystemThemeToCaptionButtons()
{
var res = Application.Current.Resources;
var frame = App.AppTitlebar as FrameworkElement;
if (frame != null)
{
if (frame.ActualTheme == ElementTheme.Dark)
{
res["WindowCaptionForeground"] = Colors.White;
}
else
{
res["WindowCaptionForeground"] = Colors.Black;
}

UpdateTitleBar(frame.ActualTheme);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ private void OnLoaded(object sender, RoutedEventArgs e)

private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
{
var resource = args.WindowActivationState == WindowActivationState.Deactivated ? "WindowCaptionForegroundDisabled" : "WindowCaptionForeground";

AppTitleBarText.Foreground = (SolidColorBrush)App.Current.Resources[resource];
App.AppTitlebar = AppTitleBarText as UIElement;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ private void OnLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)

private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
{
var resource = args.WindowActivationState == WindowActivationState.Deactivated ? "WindowCaptionForegroundDisabled" : "WindowCaptionForeground";

AppTitleBarText.Foreground = (SolidColorBrush)App.Current.Resources[resource];
App.AppTitlebar = AppTitleBarText as UIElement;
}

Expand Down

0 comments on commit 52d63a4

Please sign in to comment.