Nevron Open Vision Documentation
Getting Started / Integrating NOV in Xamarin.Mac
In This Topic
    Integrating NOV in Xamarin.Mac
    In This Topic

    NOV can be integrated in Xamarin.Mac projects. This topic provides a step-by-step tutorial on how to achieve this.

     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:

    • Start NOV Examples App - when pressed it will launch the NOV examples for Mac.
    • Open NOV Examples Project - when pressed it will launch "Finder" and open the NOV Examples folder. You can double click on the .sln file contained there ("Nevron.Nov.Examples.XamarinMac.sln") in order to open the examples in Visual Studio for Mac.
    • Open NOV Binary Files - when pressed it will launch "Finder" and open the NOV Bin folder, which contains the redistributable dlls of Nov for Xamarin Mac.
    • View NOV Documentation - when pressed it will launch your default browser and open the NOV online documentation.

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

    • Machine Id - contains the current machine id. This machine id is used to generate a development license key - see Activation for more details.
    • License Key(s) - contains the license key currently applied on the examples. At install time the NOV installation will automatically generate a 60 days trial evaluation key which you can also use in your projects for testing. 
     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" and it should have a parameterless constructor:
      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. 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.
      • Pass the type of the window you created on step 4 as a generic argument to the NNovApplicationInstaller.Install() method, for example: NNovApplicationInstaller.Install<MainWindow>().
      • If you need a custom application delegate for you Mac application, inherit it from the NNovApplicationDelegate class and add it as an argument to the NNovApplicationInstaller.Install() method. The NNovApplicationDelegate class has a property TerminateAfterLastWindowClosed.

      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();
      
                  // Apply license for redistribution here. You can skip this code when evaluating NOV.
                  // NLicenseManager.Instance.SetLicense(new NLicense("LICENSE KEY"));
      
                  // GPU rendering is enabled by default. To disable GPU rendering uncomment the following line.
                  // NApplication.EnableGPURendering = false;
      
                  // 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<MainWindow>(modules);
      
                  // Run the application
                  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.
      You can uncomment the code that applies the license key and use a valid license key code (48 characters alpha-numeric key).

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