Preview: Xamarin.Forms for macOS

DavidOrtinauDavidOrtinau David OrtinauUSForum Administrator, Xamarin Team, Insider, University Xamurai

I hope you are taking an opportunity with the latest pre-release 2.3.5.233-pre1 to experience your Xamarin.Forms apps running on macOS. It's a trip.

We want to kick off a thread to have some ongoing discussion about what's missing, what's not working, and where you'd like to see this go.

Please keep the discussion here on topic: macOS.

Posts

  • SjoerdvanNoortSjoerdvanNoort Sjoerd van Noort NLBeta ✭✭
    edited April 21

    I've started experimenting. It seems to work functionally pretty well. But is looks very ugly.

    Text looks fuzzy.

    Also VerticalTextAlignment="Center" does not seem to work (works/looks fine on iOS):

    <TableView Intent="Settings">
        <TableRoot>
            <TableSection Title="section1">
                <ViewCell >
                        <StackLayout Margin="15,0,15,0" Orientation="Horizontal">
                        <Label Text="Default" VerticalTextAlignment="Center" HorizontalOptions="StartAndExpand" />
                        <Label TextColor="Gray" x:Name="G1" Text="-"  HorizontalOptions="End" VerticalTextAlignment="Center" />
                        <Label TextColor="Gray" FontAttributes="Bold" Text="-"  HorizontalOptions="End" VerticalTextAlignment="Center" />
                    </StackLayout>
                </ViewCell>
            </TableSection>
        </TableRoot>
    </TableView>
    

    But on mac the labels are top aligned

  • HalilDoganBolakHalilDoganBolak Halil Dogan Bolak USMember ✭✭
    edited April 22

    @DavidOrtinau - First of all, thank you and the Xamarin.Forms team very much for this. Many development teams around the world were eagerly waiting for Xamarin.Forms on Mac. Yes we all have seen the release discussion thread but the amount of information & guidance there was very little. Is there a small walk through or guideline on how to add the MAC OS to an existing Visual Studio 2015 multi-platform project ? For example, I got one that is currently implemented for iOS/Droid/UWP.

  • dave.9411dave.9411 david bagno USMember
    edited April 22


    This is an amazing accomplishment. I am a long time OS X developer and have been dreaming about this for years. I hope this effort will get Xamarin's full backing and will reach the maturity of the other platforms. I have been playing with it since last night and it is very easy to implement. It seems too good to be true. I only hope that in the future it will be part of the Xamarin.Forms project template. I also hope OS X projects will be part of the Xaml previewer.

  • dave.9411dave.9411 david bagno USMember

    Any ideas how to get text to speech working on OS X in a dependency service? Can't find AVSpeechSynthesizer()

    using System;
    using AVFoundation;
    using AVKit;

    using Foundation;
    using WordGames.OSX;

    [assembly: Xamarin.Forms.Dependency(typeof(TextToSpeech_OSX))]
    namespace WordGames.OSX
    {
    public class TextToSpeech_OSX : ITextToSpeech
    {
    public TextToSpeech_OSX()
    {
    }

        public void Speak(string text)
        {
    
            var speechSynthesizer = new AVSpeechSynthesizer();
    
            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate = AVSpeechUtterance.MaximumSpeechRate / 4,
                Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                Volume = 0.5f,
                PitchMultiplier = 1.0f
            };
    
            speechSynthesizer.SpeakUtterance(speechUtterance);
        }
    }
    

    }

  • MichaelZaletelMichaelZaletel Michael Zaletel USUniversity ✭✭
    edited April 28

    A few tips for anyone trying to follow the blog tutorial here:
    https://blog.xamarin.com/preview-bringing-macos-to-xamarin-forms/

    1. Make sure that you right click on the References folder in the Mac project, choose Edit References and switch to the Projects Tab and check the box next to the Xamarin Forms Shared Project. (see attached)
    2. I am getting an error in the Mac project References folder on Xamarin.Mac (See attached) but it still seems to work
    3. Make sure to add the following using directives to AppDelegate.cs in the MacOS project
      using Xamarin.Forms;
      using Xamarin.Forms.Platform.MacOS;

    Michael Zaletel
    Enterprise Mobility @ Productive Edge
    Xamarin MVP
    Xamarin Elite Partner

  • JohnnieOdomJohnnieOdom Johnnie Odom USMember ✭✭
    edited May 2

    Note that the "Forms App" template in VS.Mac will not work with the instructions to add MacOS to Forms. You will find yourself adding a bunch of other packages to satisfy dependencies and still get build errors even after they are all added.

    If you choose the "Blank Forms App" template, the instructions work as advertised.

    I agree that this is sort of the holy grail of app development for me. If I can write in C# and deploy one standard-ish project for OS X and iOS (and maybe Windows) then I've got everything I want.

  • DavidOrtinauDavidOrtinau David Ortinau USForum Administrator, Xamarin Team, Insider, University Xamurai

    @HalilDoganBolak said:
    @DavidOrtinau - First of all, thank you and the Xamarin.Forms team very much for this. Many development teams around the world were eagerly waiting for Xamarin.Forms on Mac. Yes we all have seen the release discussion thread but the amount of information & guidance there was very little. Is there a small walk through or guideline on how to add the MAC OS to an existing Visual Studio 2015 multi-platform project ? For example, I got one that is currently implemented for iOS/Droid/UWP.

    Today you cannot add a macOS project in Visual Studio 2015 as it requires a Mac. It's basically the same requirements as a Xamarin.Mac project. https://developer.xamarin.com/guides/mac/getting_started/hello,_mac/#Requirements

    As we get further along the documentation team will provide some thorough guides. Until then, this feedback helps us know what that guide needs to cover, so thank you!

  • DavidOrtinauDavidOrtinau David Ortinau USForum Administrator, Xamarin Team, Insider, University Xamurai

    @MichaelZaletel thanks for the clarifications. I did have a bullet for "Reference your Xamarin.Forms project (shared or PCL)" but perhaps I should make that more clear. I'll update the post to reference the "using" statements. Good feedback!

  • DavidOrtinauDavidOrtinau David Ortinau USForum Administrator, Xamarin Team, Insider, University Xamurai

    @JohnnieOdom thx, we'll be reviewing the existing project templates and adding new templates to support macOS.

  • ChristopherHall.2518ChristopherHall.2518 Christopher Hall USMember

    Hi, I've just followed the instructions in the blog post and I can't build the result.
    I am using VS Mac Preview.

    When I use a 'Blank Forms App' with a shared project I see the following error:

    Line 5 of App.xaml.cs in my shared project.
    public partial class App : Application
    The type 'System.ComponentModel.INotifyPropertyChanged' is defined in an assembly that is not referenced. ...

    When I use a 'Blank Forms App' with a Portable Class Library I see the same error but on the line

    LoadApplication(new App())

    in the DidFinishLaunching override in my MacOS project.

    I can't find the System.ObjectModel assembly in the references editor.

    I have tried adding a reference to the System.ObjectModel assembly from

    /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/Xamarin.Mac/Facades

    this causes a new warning regarding assembly version mismatch which suggests adding the tag in the project file. Having added this tag the warning is removed but the error persists.

    Any suggestions as to how to fix this?

  • JeffLewisJeffLewis Jeff Lewis USMember

    First off, I'm beyond excited by this announcement. I've been waiting literally for years for it. Thank you for making my day!

    However, I'm a bit confused... Xamarin.Forms iOS apps need a Mac to develop iOS apps yet can be developed on Windows (using remote build) - why is the macOS version different? Couldn't the same tooling in VS be used for that? I'm working on an app/application for Windows, Windows UWP, iOS and Android - and very much want to add MacOS to that - but being obligated to do that on a Mac really messes up my development process.

    I can see an argument that with native macOS Xamarin development you really do need to have access to the IB part of XCode.. but you don't for Forms... and this is Forms, not pure native.

    So.. long question short: any chance that if this gets to be more widely used, the tooling changes needed to make Xamarin.Forms/macOS building on Windows via remote building might happen?

  • JeffLewisJeffLewis Jeff Lewis USMember
    edited May 11

    One omission that in retrospect is kind of obvious given where Forms comes from... but it's kind of important:

    Nothing like a <Menu> and <MenuItem> object. Obviously not needed for mobile apps.. but... this is a desktop environment. I know you can do it procedurally.. but it's an odd disconnect.

    For people getting the missing Xamarin.Mac assembly, I don't know why - but I'm finding in the most recent install of VSMac, this happens by default. it's easy to fix: remove Xamarin.Mac from the references list, then add it back. That seems to fix it.

    Christopher Hall, have you added the Xamarin.Forms nuget package to your Forms.mac project (the one you just created)? Not having it included would cause the problems you're describing. If you're using a shared/portable library to hold your common code (which is the norm), you also have to put a reference to that in the Forms.mac project. Also check the Xamarin.Mac assembly and see if it's got the red x of death next to it. If it does, delete the reference and add it back in from the Assemblies tab.

  • biaparbiapar Biagio Paruolo ITMember ✭✭

    Which is the status of this module?

  • VelocityVelocity Matthew Richardson NZMember ✭✭✭

    Will Xamarin.Forms for macOS support .NET standard?
    Reading this below had me a little worried...

    Not All NuGets are Ready for macOS
    In order to work in a macOS project, packages must target xamarinmac20. You may find that some of your beloved libraries do not yet support macOS. What can you do? Kindly send a request to the project’s maintainer to add it. Until they have support, you may need to look for alternatives.

    Eg. I raised this with James Newton-King for Newtonsoft.Json, and they have instead targeted .NET standard and would not be adding support for xamarinmac20.

  • rmarinhormarinho Rui Marinho PTMember, Insider, Beta Xamurai

    @Velocity yap we are going to support when netstandard hits 2.0 we hope

  • VelocityVelocity Matthew Richardson NZMember ✭✭✭

    @rmarinho Thanks Rui - I guess this is an important requirement if the platform is to become production-ready.
    We are eager to adopt Xamarin.Forms for macOS, but have dependencies on packages like Newtonsoft.Json. Hopefully the timeline for this isn't too far out!

  • SRaviKumarSRaviKumar S Ravi Kumar INUniversity ✭✭

    Hey David (@DavidOrtinau), Thanks for releasing this awesome feature, I have a small query, currently I can have only one window open in the application at a time, Is it possible to support multiple windows. I apologize if the question is very basic as I am pretty new to Xamarin.Mac development and there is no classes in Xamarin University on this.

  • RobertHowardRobertHoward Robert Howard USMember ✭✭

    I assume there is no xaml previewer yet for macOS? Trying to build a new app with xamarin.forms (for the sole sake of not needing to screw with XCode) and it's a bit tedious without having a live previewer.

  • DavidOrtinauDavidOrtinau David Ortinau USForum Administrator, Xamarin Team, Insider, University Xamurai

    @SRaviKumar we don't have a method within Xamarin.Forms currently to launch additional Windows. It should work using the same code/pattern you would use with Xamarin.Mac.

    https://developer.xamarin.com/guides/mac/user-interface/working-with-windows/

    Presently this would mean creating 2 Xamarin.Forms app instances which isn't what I think you'd want, so we have work to do here.

  • DavidOrtinauDavidOrtinau David Ortinau USForum Administrator, Xamarin Team, Insider, University Xamurai

    @RobertHoward no XAML Previewer support, that's correct.

  • JamesGreen.8031JamesGreen.8031 James Green GBMember ✭✭
    edited July 23

    I'm just starting out looking at this stuff. I've done Xamarin stuff for Droid and iOS before so I'm not a complete Xamarin noob but the number of inconsistencies, general weirdness and foibles I'm encountering trying to get started with this is nothing short of profound.

    I've been following these two guides for using Xamarin.Forms with .NetStandard to target MacOS.

    https://blog.xamarin.com/building-xamarin-forms-apps-net-standard/

    https://blog.xamarin.com/preview-bringing-macos-to-xamarin-forms/

    I've not gotten far at all, I'm just trying to get the projects setup in Visual Studio for Mac. These blog posts I linked to above make this all sound like it works and is very simple. My experience has thus far been the polar opposite of this.

    I created a Blank Forms App rather than a Forms App as for some reason the Forms App insists I also want a WebAPI project, which I really don't.

    After creating this I created a .NETStandard project in order to pull over the XAML files as directed inthe blog posts and now this project insists on showing every file is duplicated with only one showing the *.cs file being associated with it.

    After trying to fix this and breaking the solutions a few times I managed to get to a point where the files were listed and I wasn't getting the DuplicateCompile Items exceptions on build.

    Now the only build problem I have is:

    "Error CS0103: The name 'InitializeComponent' does not exist in the current context (CS0103) (Oracle.UI)"

    The entire .CS files is:

    using Xamarin.Forms;
    
    namespace Oracle
    {
        public partial class OraclePage : ContentPage
        {
            public OraclePage()
            {
                InitializeComponent();
            }
        }
    }
    

    I've tried the obvious fix of matching up the XAML x:class="" declaration but this has no effect at all. I've gone through the .NETSTandard blog post time and time again and as far as I can tell I haven't missed anything out yet for me this results in a very broken experience and a project that wont even compile.

    I'm referencing the very latest pre-release of Xamarin.Forms in my .NetStandard project. 2.3.5.256-pre6.

  • JamesGreen.8031JamesGreen.8031 James Green GBMember ✭✭
    edited July 24

    I've gotten a bit further with this but I'm now having a different issue. I've gotten a solution with a NetStandard Xamarin Forms project and a Cocoa App using Forms.

    However, when I compile the application I'm getting the following error:

    Error MM0023: Application name 'Oracle.exe' conflicts with another user assembly. (MM0023) (Oracle.MacOS)
    

    My Forms project and namespace is Oracle. If I change this to something like Oracle.UI and update all the namespaces in the classes the MacOS application refuses to recognise the App class from the Oracle solution.

    I'm stuck swapping between the error above and this error:

    Error CS0234: The type or namespace name 'App' does not exist in the namespace 'Oracle' (are you missing an assembly reference?) (CS0234) (Oracle.MacOS)

    Not sure how to move this forward.

    I'm assuming the issue with that there is an Oracle.dll and an Oracle.exe but I don't know what to do to fix this issue.

  • JamesGreen.8031JamesGreen.8031 James Green GBMember ✭✭

    Bump, does anyone have any info on a potential fix for this?

  • rmarinhormarinho Rui Marinho PTMember, Insider, Beta Xamurai

    Seems a namespace or dll conflit, can you post a link to the project so we take a look?

    Thanks

  • JamesGreen.8031JamesGreen.8031 James Green GBMember ✭✭

    Hi Marinho,

    You cat get the project here:

    https://github.com/jamsoft/Oracle

  • RogerHardimanRogerHardiman Roger Hardiman GBMember ✭✭
    edited August 7

    Mac builds can pick between two Target Frameworks (see Options->Build->General)
    a) Xamarin.Mac Modern
    b) Xamarin.Mac Full

    Is Xamarin Forms for Mac OS supposed to work with both frameworks?
    I can only get it working with Xamarin.Mac Modern.

    If the target is 'Full' then I have error in AppDelegate.cs
    AppDelegate.cs(30,30): Error CS0234: The type or namespace name 'MacOS' does not exist in the namespace 'Xamarin.Forms.Platform' (are you missing an assembly reference?) (CS0234)

    I'd be happy with 'Modern' except some of the Nugets I use (like NLog or Xam Plugins Gelocation) do not install in 'Modern' and wondered if I had missed something before trying to build Nlog myself.

    Thanks

  • RogerHardimanRogerHardiman Roger Hardiman GBMember ✭✭
    edited August 7

    I noticed that MacOS Xamarin Forms is calling 'OnSleep' and 'OnResume' when the desktop window loses and gains the Focus. This is no good for me as I want to keep the application running while I do other things on the Mac (like interact with the IDE or the command line)

    Is there an official way to stop these events?

    For now I've used #if ... #endif to ignore the event (although I could have used a runtime platform test)

      public void OnSleep() {
          // Ignore OnSleep with MacOS desktop applications
          #if __MACOS__
              return;
          #endif
          HandleOnSleep();
      }
    

    and define MACOS in the Project settings

  • RogerHardimanRogerHardiman Roger Hardiman GBMember ✭✭

    After reading more on the topic it looks like Xamarin Forms just targets xamarinmac20 which is the Xamarin.Mac Modern target.

  • HumbleArchitectHumbleArchitect Richard Crane USMember ✭✭

    @DavidOrtinau Thank you for working on Xamarin Forms for Mac. We are in the midst of a cross platform proof-of-concept where we would like to show Xamarin Forms for Mac. We are in a situation where we need to interop to a 3rd party library which is 32-bit. Unfortunately, the preview of Xamarin Forms does not work when we change the architecture from x86_64 to i386. Is there a plan for a preview that will support both the i386 and x86_64 architecture?

    I have attached a sample "Hello Forms" application which demonstrates the issue.

  • xyzMannxyzMann marf fram DEMember

    Hi!
    I am also trying to use Xamarin.Forms for Mac!
    I took this manual: https://blog.xamarin.com/preview-bringing-macos-to-xamarin-forms/

    and when I start my app in debug mode everything runs fine.
    But when I want to create a release build I get this error:

    Build FAILED.

    /Users/xyz-mann/Projects/MacTest/MacTest/obj/x86/Release/mmp-cache/registrar.m(6277,11): warning GD811092D: duplicate protocol definition of 'WebResourceLoadDelegate' is ignored
    /Users/xyz-mann/Projects/MacTest/MacTest/obj/x86/Release/mmp-cache/registrar.m(6496,11): warning GD811092D: duplicate protocol definition of 'CALayerDelegate' is ignored
    /Users/xyz-mann/Projects/MacTest/MacTest/obj/x86/Release/mmp-cache/registrar.m(8691,2): warning GB7F1753F: method possibly missing a [super splitView:effectiveRect:forDrawnRect:ofDividerAtIndex:] call [-Wobjc-missing-super-calls]
    /Users/xyz-mann/Projects/MacTest/MacTest/obj/x86/Release/mmp-cache/registrar.m(6637,1): error G0BB64AFA: duplicate interface definition for class 'NSToolbarItemGroup'

    And I can't access Main.Storyboard cause of this error:

    Multiple types (NSToolbarItemGroup and AppKit.NSToolbarItemGroup) registered with the same Objective-C name: NSToolbarItemGroup

    note this also happen in a blank new app as soon as I am going to install Xamarin.Forms nugget pack

    Maybe someone else also have this problem and can help me? or is it known and will be fixed?

    thanks!

  • RogerHardimanRogerHardiman Roger Hardiman GBMember ✭✭

    I also have the same problem.
    MMP: Error MM4116: Could not register the assembly 'Xamarin.Forms.Platform.macOS': error MM4118: Cannot register two managed types ('NSToolbarItemGroup, Xamarin.Forms.Platform.macOS' and 'AppKit.NSToolbarItemGroup, Xamarin.Mac') with the same native name ('NSToolbarItemGroup'). (MM4116)

  • MarkoLudolphMarkoLudolph Marko Ludolph DEMember ✭✭

    I created a PR for this bug, https://github.com/xamarin/Xamarin.Forms/pull/1097. But you don't need the storyboard at all, if you want to use Forms on the Mac.

  • DidsDids Pauli Jokela FIMember ✭✭
    edited August 14

    Also seeing the same duplicate symbol error. Are any of you using a .NET Standard libraries with Forms by any chance? I am, and just wondering if that's affecting it.

    EDIT: Nope, tried with a shared project but with same results. I'm using VS4Mac with beta channel, so I guess that could also be related?

  • RogerHardimanRogerHardiman Roger Hardiman GBMember ✭✭

    Found a bug with DisplayActionSheet on XF for MacOS.
    If the list is long then the pop-up does not have any scroll bars to show the whole list of items and no way to reach the Cancel button at the bottom of the popup

  • RogerHardimanRogerHardiman Roger Hardiman GBMember ✭✭

    Bug 58779 has been filed for the DisplayActionSheet bug (when the list has 15 items and is taller than the screen height)

    I will add that I've now ported 2 Xamarin Forms applications to Xamarin Forms on the Mac. Both have custom renders which I ported over too. It is wonderful.

  • DavidOrtinauDavidOrtinau David Ortinau USForum Administrator, Xamarin Team, Insider, University Xamurai

    Thanks all for the feedback and helping hammer through these issues.

    Lots of macOS related fixes including the PR1097 are now available in 2.4.0-pre1. Update and continue to let us know how you get on.

  • RogerHardimanRogerHardiman Roger Hardiman GBMember ✭✭

    Found another bug. I use XF Properties classes to save and load user settings.
    Properties are serialised into a file called PropertyStore.forms which should be in IsolatedStorage.

    However on my Mac desktop, the file is located at /Users/myname/.config/.issolated_storage/PropertyStore.forms

    Two different XF Mac OS Desktop apps are accessing the same file and conflicting.
    Something is wrong as the properties are not in sub-directories that are app specific (so not really IsolatedStorage)

Sign In or Register to comment.