Preview: Xamarin.Forms for macOS

DavidOrtinauDavidOrtinau David OrtinauUSXamarin 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 USXamarin 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 USXamarin 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 USXamarin 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

Sign In or Register to comment.