Forum Xamarin.Mac

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

VS for Mac: MessageBox / MessageDialog / Popup to user

renglundrenglund Member ✭✭

Hello everyone!

I am currently using Visual Studio for Mac and am struggling to find an equivalent way of displaying a popup message to the user inside a GUI the same way " MessageBox.Show("Invalid amount", "Error") does on Visual Studio for Windows. Is there such a method and if so, does it require using a specific library?

Best Regards
Robert

Best Answer

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    Accepted Answer

    In general the Apple HIG suggests minimizing such alerts and to show these errors and warnings in other ways.

    However, if you need it you should look at the NSAlert class. Something like:

    NSAlert.WithMessage ("Hello world", "OK", null, null, "").RunModal ();
    

Answers

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    Accepted Answer

    In general the Apple HIG suggests minimizing such alerts and to show these errors and warnings in other ways.

    However, if you need it you should look at the NSAlert class. Something like:

    NSAlert.WithMessage ("Hello world", "OK", null, null, "").RunModal ();
    
  • renglundrenglund Member ✭✭
    Hi Chris Hamons!

    Thanks for the fast reply!

    Is it ” using MonoMac.AppKit- Library that makes NSAlert.WithMessage work? Do I create an instance of NSAlert- class?

    Best regards
    Robert
  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    If you have a MonoMac.AppKit then you are using Classic XamMac, which is 32-bit only and has a number of longstanding issues. See this blog post for more information.

    You really should migrate to Xamarin.Mac Unified, which is described on that blog post.

    At a high level, that line is instancing an instance of NSAlert and running the RunModal method to show the popup.

    At a lower level, you can read about the interactions with Objective-C here

    If you are new to Xamarin.Mac I would suggest starting with the documentation linked in the FAQ

Sign In or Register to comment.