Nevron Open Vision Documentation
Getting Started / Integrating NOV in WPF for C# and VB.NET
In This Topic
    Integrating NOV in WPF for C# and VB.NET
    In This Topic

    There are 3 ways in which NOV can integrate in a WPF application:

     Designer (Toolbox) Integration

    You can simply drag and drop NOV components from the Visual Studio Toolbox. The Visual Studio Designer will automatically add the necessary dll references to your project and you can start coding directly. The following code snippet shows how to say "Hello World from Nevron Open Vision" using this type:

    1. Drag and Drop the NLabelControl from the "Nevron NOV Controls" toolbox category to the main windows of your application.

    2. Open the MainWindow.xaml file and make sure that the label control has a name:

    Creating a NOV label in XAML
    Copy Code
    <WpfControls:NLabelControl Name="nLabelControl1" HorizontalAlignment="Left" Height="100" Margin="192,131,0,0" VerticalAlignment="Top" Width="100"/>
    

    3. Write the following code in MainWindow constructor:

    Installing NOV in WPF
    Copy Code
    using System.Windows;
    
    namespace WpfApplication1
    {
         /// <summary>
         /// Interaction logic for MainWindow.xaml
         /// </summary>
         public partial class MainWindow : Window
         {
             public MainWindow()
             {
                 InitializeComponent();
                 nLabelControl1.Widget.Text = "Hello World from NOV";
             }
         }
    }
    

    That's it - you have created your first WPF application using a NOV control. For more information check out the Integrating NOV from the Visual Studio Toolbox topic.

     Coded Integration for C# and VB.NET

    1. Create a new WPF project in Visual Studio

    • From File Menu - Choose New Project
    • Select the "Visual C# -> WPF Application" or "Visual Basic -> WPF Application"
    • Click OK
    This step is not mandatory, because you can integrate NOV in an already existing WPF 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 assembly.
    • Nevron.Nov.Host.WinBase.dll - base assembly for Windows presentation hosts (WinForm and WPF). 
    • Nevron.Nov.Host.Wpf.dll - presentation host for WPF. 
    • Nevron.Nov.Barcode.dll - NOV Barcode.
    • Nevron.Nov.Chart.dll - NOV Chart.
    • Nevron.Nov.Diagram.dll - NOV Diagram.
    • Nevron.Nov.Grid.dll - NOV Grid.
    • Nevron.Nov.Schedule.dll - NOV Schedule.
    • Nevron.Nov.Text.dll - NOV Text.

    3. If your WPF application is for .NET Framework 5.0 or above, reference the Nuget package: System.Drawing.Common, version 5.0.0

    4. Initialize the NOV Application

    For C# WPF projects expand the App.xaml file in the Solution Explorer of Visual Studio and double click the App.xaml.cs file to open it. Then replace its content with the following C# code:

    C# - Installing NOV for WPF
    Copy Code
    using System.Windows;
    
    using Nevron.Nov.Barcode;
    using Nevron.Nov.Chart;
    using Nevron.Nov.Diagram;
    using Nevron.Nov.Grid;
    using Nevron.Nov.Schedule;
    using Nevron.Nov.Text;
    using Nevron.Nov.Windows.Wpf;
    
    namespace NovWpfApplication
    {
        /// <summary>
        /// Interaction logic for App.xaml
        /// </summary>
        public partial class App : Application
        {
            protected override void OnStartup(StartupEventArgs e)
            {
                base.OnStartup(e);
    
                // TODO: Apply license for redistribution here. You can skip this code when evaluating NOV.
                // NLicenseManager.Instance.SetLicense(new NLicense("LICENSE KEY"));
    
                // Install Nevron Open Vision for WPF
                NNovApplicationInstaller.Install(
                    NBarcodeModule.Instance,
                    NTextModule.Instance,
                    NChartModule.Instance,
                    NDiagramModule.Instance,
                    NScheduleModule.Instance,
                    NGridModule.Instance);
            }
        }
    }
    

    For Visual Basic WPF applications open the Application.xaml file and add the following attribute to the Application XAML element: Startup="Application_Startup". Then expand the Application.xaml file in the Solution Explorer of Visual Studio and double click the Application.xaml.vb file to open it. Replace its content with the following VB code:

    VB.NET - Installing NOV for WPF
    Copy Code
    Imports Nevron.Nov
    Imports Nevron.Nov.Barcode
    Imports Nevron.Nov.Chart
    Imports Nevron.Nov.Diagram
    Imports Nevron.Nov.Grid
    Imports Nevron.Nov.Schedule
    Imports Nevron.Nov.Text
    Imports Nevron.Nov.Windows.Wpf
    
    Class Application
        Private Sub Application_Startup(sender As Object, e As StartupEventArgs)
            ' TODO: Apply license for redistribution here. You can skip this code when evaluating NOV.
            ' NLicenseManager.Instance.SetLicense(New NLicense("LICENSE KEY"))
    
            ' Install Nevron Open Vision for Windows Forms
            NNovApplicationInstaller.Install(
                    NBarcodeModule.Instance,
                    NTextModule.Instance,
                    NChartModule.Instance,
                    NDiagramModule.Instance,
                    NScheduleModule.Instance,
                    NGridModule.Instance)
        End Sub
    End Class
    

    See Hosting NOV in your Application for more information about modules.

    After purchasing a license for NOV, you should uncomment the code that applies the license key and use a valid license key code (48 characters alpha-numeric key).

    5. Say Hello World from NOV

    For C# projects open the MainWindow.xaml.cs file and replace its content with the following code:

    C# - Hello World from NOV
    Copy Code
    using System.Windows;
    using Nevron.Nov.UI;
    using Nevron.Nov.Windows.Wpf;
    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                // Add a NOV widget inside the window
                NLabel sayHelloWorldLabel = new NLabel("Hello World from Nevron Open Vision");
                Content = new NNovWidgetHost<NLabel>(sayHelloWorldLabel);
            }
        }
    }
    

    For Visual Basic (VB.NET) projects open the NMainWindow.xaml.vb file and replace its content with the following code:

    VB.NET - Hello World from NOV
    Copy Code
    Imports Nevron.Nov
    Imports Nevron.Nov.UI
    Imports Nevron.Nov.Windows.Wpf
    
    Class MainWindow
        Public Sub New()
            ' This call is required by the designer.
            InitializeComponent()
            ' Add any initialization after the InitializeComponent() call.
            Content = New NNovWidgetHost(Of NWidget)(CreateNovContent())
        End Sub
    
        Private Function CreateNovContent() As NWidget
            Dim label As NLabel = New NLabel("Hello World from Nevron Open Vision")
            label.TextAlignment = ENContentAlignment.MiddleCenter
            Return label
        End Function
    End Class
    

    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 WPF. The sample just makes a simple label, as content of the NNovWidgetHost WPF Control, but this control can actually contain any NOV widget. See the UI Overview topic for an overview of the User Interface that comes along with NOV.

    See Also