Nevron Open Vision Documentation
Hosting 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 please read on.

  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.
    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.
    • Reference other NOV assemblies for Mac if you need to:
      • 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. Initialize the NOV Application

    Open the "Main.cs" file and ensure that 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 NovTestApp
    {
        static class MainClass
        {
            static void Main(string[] args)
            {
                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);
                NSApplication.Main(args);
            }
        }
    }
    

    The installation will automatically generate an evaluation license key, which you can obtain from the License Key text box in the NevronOpenVision application.

  4. Say Hello World from NOV

    You should then create a NOV widget host and set it to the ContentView property of the application's main window. 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.

    The sample code below when placed in the "MainWindow.cs" file creates a NOV widget containing a label that shows the text "Hello World":

    Say Hello World from NOV
    Copy Code
    using System;
    using AppKit;
    using Foundation;
    
    using Nevron.Nov;
    using Nevron.Nov.Mac;
    using Nevron.Nov.UI;
    
    namespace NovTestApp
    {
        public partial class MainWindow : NSWindow
        {
            public MainWindow(IntPtr handle) : base(handle)
            {
                ContentView = new NNovWidgetHost(CreateNovContent());
            }
    
            [Export("initWithCoder:")]
            public MainWindow(NSCoder coder) : base(coder)
            {
                ContentView = new NNovWidgetHost(CreateNovContent());
            }
    
            public override void AwakeFromNib()
            {
                base.AwakeFromNib();
            }
    
            private NWidget CreateNovContent()
            {
                NLabel label = new NLabel("Hello World");
                label.TextAlignment = ENContentAlignment.MiddleCenter;
                return label;
            }
        }
    }
    

    Run the application - it should display a simple form with a "Hello World from Nevron Open Vision" label inside.

    This is as much as is required to host some NOV content in Xamarin Mac.

  5. Make the application quit when last window closes

    Last but not least, if you want your application to quit when the last of its windows is closed, you should override the ApplicationShouldTerminateAfterLastWindowClosed method of you application's app delegate (it's located in the "AppDelegate.cs" file) to return true:

    Make the application quit when last window closes
    Copy Code
    using AppKit;
    using Foundation;
    
    namespace NovTestApp
    {
        [Register("AppDelegate")]
        public class AppDelegate : NSApplicationDelegate
        {
            MainWindowController mainWindowController;
    
            public AppDelegate()
            {
            }
    
            public override void DidFinishLaunching(NSNotification notification)
            {
                mainWindowController = new MainWindowController();
                mainWindowController.Window.MakeKeyAndOrderFront(this);
            }
    
            public override void WillTerminate(NSNotification notification)
            {
                // Insert code here to tear down your application
            }
    
            public override bool ApplicationShouldTerminateAfterLastWindowClosed(NSApplication sender)
            {
                return true;
            }
        }
    }
    
See Also

UI

Send Feedback