Nevron Open Vision Documentation
Integrating NOV in Xamarin.Mac

NOV can integrate with Xamarin.Mac projects. This topic teaches you how to achieve integration with a Xamarin.Mac project.

Download and Install NOV

Download the NevronOpenVision.XamarinMac package.

After you install the package go to Applications and launch Nevron Open Vision. The application has the following UI items:

Below those buttons you can also view the generated machine id and the current evaluation key.

Integrate in a Xamarin.Mac Project

The instructions below shows how to integrate Nevron Open Vision in a Xamarin.Mac project created with Visual Studio for Mac. If you want to download a ready project, which you can directly compile and run with Visual Studio for Mac, click here to download the NovTestApp project. All you have to do is to extract the project to a directory of your choice on your Mac and add the correct references to the NOV assemblies.

If you prefer to follow the instructions instead of loading the ready project or you want to integrate NOV in an existing Xamarin.Mac project, then you can use the following instructions.

In this step by step tutorial, we are going to create a very simple .storyboar/.xib-less application for Xamarin.Mac. In such applications, the entire UI is created from code only and we'll have to create window and window, controller classes. Fortunately, this is very simple and takes a minimal amount of code.

  1. Create a new Cocoa App project in Visual Studio for Mac.
    • From the "File" menu select "New Solution"
    • Select the Mac -> App -> Cocoa App (C#) project template and follow the wizard. When asked to input the application name enter NevronTestApp - this will ensure that you can copy paste the code examples below.

    This step is not mandatory, because you can integrate NOV in an already existing Xamarin.Mac project. It is performed just for the purpose of making a complete installation scenario.

  2. Reference the NOV Assemblies
    Ensure that your application references the following NOV dlls:
    • Nevron.Nov.Presentation.dll - core NOV portable assembly. Contains common NOV ui widgets like labels, buttons, drop downs, menus, toolbars, ribbon, etc.
    • Nevron.Nov.Host.XamarinMac.dll - presentation host for XamarinMac.                       
    • Nevron.Nov.Barcode - barcode component.
    • Nevron.Nov.Chart - chart component.
    • Nevron.Nov.Diagram - diagram component. Requires the Barcode and Text components.
    • Nevron.Nov.Grid - grid component.
    • Nevron.Nov.Schedule - schedule component. Requires the Barcode component.
    • Nevron.Nov.Text - rich text component. Requires the Barcode component.
    You can reference the dlls directly from the System/Applications/NevronOpenVision.XamarinMac/Contents/Bin folder or copy those dlls to a folder which is more convenient for referencing.

  3. Remove Main.storyboard and ViewController.cs from the project
    Right click on the Main.storyboard and ViewController.cs files from project.

  4. Add a MainWindow.cs file
    Right click on the NevronTestApp project and select Add New File / Empty Class. The name of the class should be "MainWindow":
    Installing NOV for Xamarin.Mac
    Copy Code
    using AppKit;
    using CoreGraphics;
    
    using Nevron.Nov;
    using Nevron.Nov.Mac;
    using Nevron.Nov.UI;
    namespace NevronTestApp
    {
        public class MainWindow : NSWindow
        {
            public MainWindow()
                : base(new CGRect(0, 0, 400, 400), NSWindowStyle.Resizable | NSWindowStyle.Titled | NSWindowStyle.Closable, NSBackingStore.Buffered, false)
            {
                this.IsZoomed = true;
                NLabel label = new NLabel("Hello World");
                label.TextAlignment = ENContentAlignment.MiddleCenter;
               
                ContentView = new NNovWidgetHost(label);
            }
        }
    }
    

    This code creates a new NOV widget host that contains a simple label. The content of the NOV widget host should be set to a NOV widget and can be any NOV widget, for example a label, a button, a document view (drawing view, schedule view, rich text view, etc.) a panel with other widgets and so on. See the UI Overview topic for an overview of the NOV User Interface.

  5. Modify the AppDelegate.cs

    Modfy the AppDelegate.cs file by adding the following code that shows the main window when the application finishes loading:

    Installing NOV for Xamarin.Mac
    Copy Code
    using AppKit;
    using Foundation;
    namespace NevronTestApp
    {
        [Register("AppDelegate")]
        public class AppDelegate : NSApplicationDelegate
        {
            public AppDelegate()
            {            
            }
           
            public override void DidFinishLaunching(NSNotification notification)
            {
                MainWindow mainWindow = new MainWindow();            
                mainWindow.MakeKeyAndOrderFront(this);
            }
           
            public override bool ApplicationShouldTerminateAfterLastWindowClosed(NSApplication sender)
            {
                // Makes the application close after its last window is closed
                return true;
            }
    
            public override void WillTerminate(NSNotification notification)
            {
                // Insert code here to tear down your application
            }
        }
    }
    
    IMPORTANT: Please note that the code also overrides ApplicationShouldTerminateAfterLastWindowClosed in order to inform the application that it should terminate after the last window is closed. If this is not the desired behavior you can remove this method override.

  6. Initialize the NOV Application
    Open the "Main.cs" file and ensure that in the Main method:
    • The NSApplication.Init() method is called first. This will make it possible to use Apple objects like NSObject.
    • The NNovApplicationInstaller.Install() method is called before the Xamarin.Mac application runs the main form of the application.

    Installing NOV for Xamarin.Mac
    Copy Code
    using AppKit;
    using Nevron.Nov;
    using Nevron.Nov.Barcode;
    using Nevron.Nov.Chart;
    using Nevron.Nov.Diagram;
    using Nevron.Nov.Grid;
    using Nevron.Nov.Mac;
    using Nevron.Nov.Schedule;
    using Nevron.Nov.Text;
    
    namespace NevronTestApp
    {
        static class MainClass
        {
            static void Main(string[] args)
            {
                // Always initialize the NSApplication first
                NSApplication.Init();
    
                // Set license (you can skip this while evaluating NOV)
                NLicenseManager.Instance.SetLicense(new NLicense("LICENSE KEY"));
    
                // Install NOV
                NModule[] modules = new NModule[]
                {
                    // Add the modules you want to use here
                    NBarcodeModule.Instance,
                    NChartModule.Instance,
                    NDiagramModule.Instance,
                    NGridModule.Instance,
                    NScheduleModule.Instance,
                    NTextModule.Instance
                };
    
                NNovApplicationInstaller.Install(modules);
    
                // Set new application delegate
                NSApplication.SharedApplication.Delegate = new AppDelegate();
                NSApplication.SharedApplication.Run();
            }
        }
    }
    
    The installation will automatically generate an evaluation license key, which you can obtain from the License Key text box in the NevronOpenVision application.

  7. Run the Application
    Congratulations you've just created your first Mac app with Nevron Open Vision.
See Also

UI

Send Feedback