-1

I am colour blind and would like to take advantage of the dark mode in MacOS for my app.

I saw this but I don't know if it is correct for my context.

Being colourblind I am not in a position to choose my own colour scheme. I just want the standard dark mode.

At the moment my window (which is all in just XAML / Xamarin.Forms 4.8 with hard coded text) looks like this:

enter image description here

Any pointers on a walk through for Visual Studio for Mac appreciated.


Update 1

If I add the following control:

<Label x:Name="currentThemeLabel" Text="{AppThemeBinding Dark='Dark1', Light='Light2',Default='Default3'}"/>

The result on my window is Light2. My MacOS app seems to be forced to be Light mode.


Update 2

I added a button handler to test this:

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();
}

And it displays:

enter image description here

So the theme in the app is Unspecified. According to this info it states:

Unspecified will be returned when the operating system does not have a specific user interface style to request. An example of this is on devices running versions of iOS older than 13.0.

I am using macOS Big Sur (latest update as of 11 Feb 2021) and it is set to Dark:

enter image description here

So I still don't understand why the app returned Unspecified instead of Dark.

This is my AppDelegate.cs if it helps:

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);
        }
    }
}
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • @Cfun I mean the dark mode that the MocOS uses when you set teh system as Dark mode. In their docs they simply say to define a theme ans they show some colours. How do I know what those colours are based on? – Andrew Truckle Feb 10 '21 at 19:34
  • @Cfun And the examples there are for iOS and Android - not MacOS. – Andrew Truckle Feb 10 '21 at 19:36
  • For the example have you tried it on MacOS and was not working (I guess it will work)? for the other point I don't think Xamarin is aware about which color MacOS is using for which theme, you will probably need to define them yourself. – Cfun Feb 10 '21 at 19:40
  • @Cfun I confess I have not tried it. I am new to coding for the Mac environment and don't want to blindly paste code documented for different platforms. – Andrew Truckle Feb 10 '21 at 20:02
  • I learned alot here: https://www.youtube.com/watch?v=Q2F51yNHv_I but for some reason my "app" always seems to be "light mode" no matter what my "system" mode is. – Andrew Truckle Feb 10 '21 at 20:49
  • From what I have read I should not need to do any static resources. The app should out of the box use the native theme settings and since these are all normal controls it should just render. For a few minutes I managed, somehow to get it to start rendering dark but then went back to light. I removed all of my code that I added this evening. Oh well. – Andrew Truckle Feb 10 '21 at 23:08
  • Hi, whehter you are developing a macos application in Xamarin Forms? – Junior Jiang Feb 11 '21 at 02:23
  • @JuniorJiang-MSFT Yes, Cocoa App. – Andrew Truckle Feb 11 '21 at 05:06
  • @AndrewTruckle Okey, you could have a look at [this document](https://developer.apple.com/documentation/xcode/supporting_dark_mode_in_your_interface?language=objc) from Apple. – Junior Jiang Feb 11 '21 at 06:33
  • @JuniorJiang-MSFT I had already read that document last night. As you can see part way through it clearly states that the system will automatically do rendering based on the users theme anyway. That is not happening for me. – Andrew Truckle Feb 11 '21 at 08:17

1 Answers1

0

I ungraded to the latest 5.x snd it shows dark now:

enter image description here

The only controls that don't change properly if I toggle the theme is the Button objects.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • Although I should point out that rendering is odd (shows alot of white) for `NavigationPage` derived GUI. But `TabbedPage` is OK. – Andrew Truckle Feb 15 '21 at 15:23