Getting Started with NOV in Silverlight using only code

Getting Started with NOV in Silverlight using only code



1. Create a new Silverlight project in Visual Studio
  • From File Menu - Choose New Project
  • Select the Visual C# - Silverlight Application Template
  • Click OK

NB: You need to target Silverlight 5.



This step is not mandatory, because you can integrate NOV in an already existing Silverlight 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;
Nevron.Nov.Host.Silverlight.dll - presentation host for Silverlight;




These assemblies are located in NOV installation folder: C:\Program Files (x86)\Nevron Software\Nevron Open Vision VERSION\Bin\SL

3. Initialize the NOV Application
Open the App.xaml.cs file and ensure that it it has the following code:

using Nevron.Nov;
using Nevron.Nov.Windows;
using System;
using System.Windows;
 
namespace SilverlightApplication1
{
    public partial class App : Application
    {
        public App()
        {
            this.Startup += this.Application_Startup;
            this.Exit += this.Application_Exit;
            this.UnhandledException += this.Application_UnhandledException;
            InitializeComponent();
        }
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // Apply license to the application here.
            NLicenseManager.Instance.SetLicense(new NLicense("LICENSE KEY"));
 
            NModule[] modules = new NModule[] {
      // TODO: Create modules here
   };
 
            // install Nevron Open Vision for Silverlight
            NNovApplicationInstaller.Install(modules);
            // the installation of Nevron Open Vision for Silverlight,
            // replaces the RootVisual of the application, so you need
            // to place your default main page as content of the user layer
            NSLDesktop.Instance.UserLayer.Content = new MainPage();
        }
        private void Application_Exit(object sender, EventArgs e)
        {
        }
        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            // If the app is running outside of the debugger then report the exception using
            // the browser's exception mechanism. On IE this will display it a yellow alert
            // icon in the status bar and Firefox will display a script error.
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                // NOTE: This will allow the application to continue running after an exception has been thrown
                // but not handled.
                // For production applications this error handling should be replaced with something that will
                // report the error to the website and stop the application.
                e.Handled = true;
                Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
            }
        }
        private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
        {
            try
            {
                string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
                errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
                System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
            }
            catch (Exception)
            {
            }
        }
    }
}

The important code here is in the Application_Startup event handler. It calls the Install method of the NOV Silverlight application installer. NOV for Silverlight requires to have control over the RootVisual of your Silverlight application, to implement a custom windowing system, that very much resembles Microsoft Windows. That is why the installation sets the RootVisual of the application to be the NSLDesktop.Instance Silverlight element. The NSLDesktop is having a UserControl that is intended to host any Silverlight content - in this example we place the MainPage as content of this user control, but it can be any other Silverlight content.

4. Say Hello World from NOV
Open the MainPage.xaml.cs file and replace its content with the following code:

using Nevron.Nov.UI;
using Nevron.Nov.Windows;
using System.Windows.Controls;
 
namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            // Add a NOV widget inside the form
            NLabel sayHelloWorld = new NLabel("Hello World from Nevron Open Vision");
            Content = new NNovWidgetHost<NLabel>(sayHelloWorld);
        }
    }
}

Run the application - it should launch your browser with a "Hello World from Nevron Open Vision" label inside.

Important: the Silverlight plugin may not be supported by your browser.


This is as much as is required to host some NOV content in Silverlight. From now on you can forget everything you know about Silverlight, since you will not need it when developing with NOV.

The sample just makes a simple label, as content of the NNovWidgetHost Silverlight Control, but this control can actually contain any NOV widget. See the NOV Help Documentation -> UI Overview topic for an overview of the User Interface that comes along with NOV.

 
Download Free Trial  Help Documentation
Send Feedback

Article ID: 241, Created On: 7/22/2016, Modified: 8/12/2016