如何解决如何更改我的项目以使用 MacOS DarkMode 构建
我是色盲,想在我的应用中使用 MacOS 中的暗模式。
我看到了 this,但我不知道它是否适合我的上下文。
作为色盲,我无法选择自己的配色方案。我只想要标准的黑暗模式。
目前我的窗口(全是 XAML / Xamarin.Forms 4.8 硬编码文本)看起来像这样:
感谢有关 Visual Studio for Mac 的任何指导。
更新 1
如果我添加以下控件:
<Label x:Name="currentThemeLabel" Text="{AppThemeBinding Dark='Dark1',Light='Light2',Default='Default3'}"/>
我的窗口上的结果是 Light2。我的 MacOS 应用似乎被强制设为 Light 模式。
更新 2
void OnButtonAddElderClicked(object sender,EventArgs e)
{
var alert = new NSAlert()
{
AlertStyle = NSAlertStyle.informational,informativeText = "The active theme is: " + Application.Current.UserAppTheme.ToString(),MessageText = "Active Theme",};
alert.RunModal();
}
它显示:
所以应用中的主题是Unspecified
。根据这个 info 它指出:
Unspecified
。例如,在运行 13.0 之前版本的 iOS 的设备上。
我使用的是 macOS Big Sur(截至 2021 年 2 月 11 日的最新更新)并且设置为深色:
所以我仍然不明白为什么应用返回 Unspecified
而不是 Dark
。
如果有帮助,这是我的AppDelegate.cs
:
using AppKit;
using Foundation;
using VisitsRota;
using Xamarin.Forms;
using Xamarin.Forms.Platform.MacOS;
namespace VisitsRota.MacOS
{
[Register("AppDelegate")]
public class AppDelegate : FormsApplicationDelegate
{
NSWindow window;
public AppDelegate()
{
var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;
var rect = new CoreGraphics.CGRect(200,1000,1024,768);
window = new NSWindow(rect,style,NSbackingStore.Buffered,false);
window.Title = "Visits Rota for Mac";
window.TitleVisibility = NSWindowTitleVisibility.Hidden;
}
public override NSWindow MainWindow
{
get { return window; }
}
public override void DidFinishLaunching(NSNotification notification)
{
Forms.Init();
LoadApplication(new App());
base.DidFinishLaunching(notification);
}
}
}
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。