Skip to content

Commit 009e5e2

Browse files
committed
fix: PlatformSetStyle invalid on Windows
1 parent fd8ecd8 commit 009e5e2

File tree

6 files changed

+43
-34
lines changed

6 files changed

+43
-34
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ using MauiBlazorToolKit.Platform
7878
#endif
7979
```
8080

81-
> TitleBar.SetStyle() temporarily invalid, cannot change the text color of the button
82-
8381
## AppStoreLauncher (opens the default app store)
8482
`AppStoreLauncher` allows you to open the default app store
8583

README.zh-CN.md

-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ using MauiBlazorToolKit.Platform
7878
#endif
7979
```
8080

81-
> TitleBar.SetStyle() 暂时无效,不能改变按钮的文本颜色
82-
8381
## AppStoreLauncher(打开默认应用商店)
8482
`AppStoreLauncher` 允许你打开默认的应用商店
8583

src/MauiBlazorToolkit/MauiBlazorToolkit.Sample/MainPage.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xmlns:mauiBlazorToolkit="clr-namespace:MauiBlazorToolkit.Behaviors;assembly=MauiBlazorToolkit"
77
BackgroundColor="{DynamicResource PageBackgroundColor}">
88
<ContentPage.Behaviors>
9-
<mauiBlazorToolkit:TitleBarBehavior TitleBarColor="#fff" TitleBarStyle="LightContent"></mauiBlazorToolkit:TitleBarBehavior>
9+
<mauiBlazorToolkit:TitleBarBehavior TitleBarColor="#fff" TitleBarStyle="DarkContent"></mauiBlazorToolkit:TitleBarBehavior>
1010
</ContentPage.Behaviors>
1111
<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
1212
<BlazorWebView.RootComponents>

src/MauiBlazorToolkit/MauiBlazorToolkit/Extensions/AppBuilderExtensions/AppBuilderExtensions.shared.cs

+18-18
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@ public static MauiAppBuilder UseMauiBlazorToolkit(this MauiAppBuilder builder, A
1515
builder.ConfigureLifecycleEvents(events =>
1616
{
1717
#if WINDOWS
18-
events
19-
.AddWindows(windows =>
18+
events.AddWindows(windows =>
19+
{
20+
windows.OnWindowCreated((window) =>
2021
{
21-
windows.OnWindowCreated((window) =>
22+
if (Options.InternalTitleBar)
2223
{
23-
if (Options.InternalTitleBar)
24-
{
25-
TitleBar.Initialize();
26-
}
27-
});
24+
TitleBar.Initialize();
25+
}
2826
});
27+
});
2928
#elif MACCATALYST
30-
events.AddiOS(ios => ios
31-
.FinishedLaunching((window, args) =>
32-
{
33-
if (Options.InternalTitleBar)
34-
{
35-
TitleBar.Initialize();
36-
}
37-
return true;
38-
})
39-
);
29+
events.AddiOS(ios =>
30+
{
31+
ios.FinishedLaunching((window, args) =>
32+
{
33+
if (Options.InternalTitleBar)
34+
{
35+
TitleBar.Initialize();
36+
}
37+
return true;
38+
});
39+
});
4040
#endif
4141
});
4242

src/MauiBlazorToolkit/MauiBlazorToolkit/Platform/TitleBar/TitleBar.macos.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,38 @@
22

33
namespace MauiBlazorToolkit.Platform;
44

5-
[SupportedOSPlatform("MacCatalyst10.0"), UnsupportedOSPlatform("MacOS")]
5+
[SupportedOSPlatform("MacCatalyst11.0"), UnsupportedOSPlatform("MacOS")]
66
static partial class TitleBar
77
{
88
static UIKit.UIWindow? NativeWindow =>
99
(UIKit.UIWindow?)Application.Current?.Windows.FirstOrDefault()?.Handler?.PlatformView;
1010

1111
static ResourceDictionary? Resources => Application.Current?.Resources;
12+
1213
static void PlatformSetColor(Color color)
1314
{
14-
if (Resources == null) return;
15+
if (Resources is null) return;
1516
Resources["PageBackgroundColor"] = color;
1617
}
1718

1819
static void PlatformSetStyle(TitleBarStyle style)
1920
{
20-
if (Resources == null) return;
21+
if (Resources is null) return;
2122
var color = style switch
2223
{
2324
TitleBarStyle.Default => Colors.Black,
2425
TitleBarStyle.LightContent => Colors.White,
2526
TitleBarStyle.DarkContent => Colors.Black,
26-
_ => throw new NotSupportedException($"{nameof(TitleBarStyle)} {style} is not yet supported on iOS")
27+
_ => throw new NotSupportedException($"{nameof(TitleBarStyle)} {style} is not yet supported on MacCatalyst")
2728
};
2829
Resources["PrimaryTextColor"] = color;
2930
}
3031

3132
public static void Initialize()
3233
{
33-
if (NativeWindow == null) return;
34+
if (NativeWindow is null) return;
3435
var titleBar = NativeWindow.WindowScene?.Titlebar;
35-
if (titleBar == null) return;
36+
if (titleBar is null) return;
3637
titleBar.TitleVisibility = UIKit.UITitlebarTitleVisibility.Hidden;
3738
}
3839
}

src/MauiBlazorToolkit/MauiBlazorToolkit/Platform/TitleBar/TitleBar.windows.cs

+17-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ namespace MauiBlazorToolkit.Platform;
77
[SupportedOSPlatform("Windows")]
88
static partial class TitleBar
99
{
10-
static Microsoft.UI.Xaml.Window? NativeWindow =>
10+
static Microsoft.UI.Xaml.Window? NativeWindow =>
1111
(Microsoft.UI.Xaml.Window?)Application.Current?.Windows.FirstOrDefault()?.Handler?.PlatformView;
12+
1213
static Microsoft.UI.Xaml.ResourceDictionary Resources =>
1314
Microsoft.UI.Xaml.Application.Current.Resources;
1415

1516
static void PlatformSetColor(Color color)
16-
{
17+
{
1718
Resources["TitleBarBackground"] = color.ToWindowsColor();
1819
if (NativeWindow is not null && NativeWindow.Content is Microsoft.UI.Xaml.FrameworkElement fe)
1920
{
@@ -24,9 +25,20 @@ static void PlatformSetColor(Color color)
2425
}
2526
}
2627

27-
static void PlatformSetStyle(TitleBarStyle style)
28-
{
29-
//图标颜色暂时无法更改
28+
static void PlatformSetStyle(TitleBarStyle style)
29+
{
30+
if (NativeWindow is not null)
31+
{
32+
var color = style switch
33+
{
34+
TitleBarStyle.Default => Colors.Black,
35+
TitleBarStyle.LightContent => Colors.White,
36+
TitleBarStyle.DarkContent => Colors.Black,
37+
_ => throw new NotSupportedException($"{nameof(TitleBarStyle)} {style} is not yet supported on Windows")
38+
};
39+
var titleBar = NativeWindow.AppWindow.TitleBar;
40+
titleBar.ButtonForegroundColor = color.ToWindowsColor();
41+
}
3042
}
3143

3244
public static void Initialize()

0 commit comments

Comments
 (0)