LEAD Technologies, Inc

Working with Automated Annotations in Silverlight

Take the following steps to start a project and to add some code that will demonstrate the automated annotation features of the LEADTOOLS Silverlight Control.

  1. Start Visual Studio .NET 2008.
  2. Start with the project that you created in Loading and displaying an image in Silverlight.
  3. In the "Solution Explorer" window, right-click on the "References" folder for the Silverlight project and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, browse to the "<LEADTOOLS_INSTALLDIR>\Bin\Silverlight" or "<LEADTOOLS_INSTALLDIR>\Bin\Silverlight4" folder (depending on your target Silverlight version), and select Leadtools.Windows.Annotations.dll.
  4. Open the Page.xaml file and copy the below xaml code into the editor:

    [XAML]

                <UserControl x:Class="Load_And_Display.MainPage"
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                   xmlns:Leadtools_Windows_Controls="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls"
                   Width="800" Height="800">
                   <Grid x:Name="LayoutRoot" Background="White">
                      <StackPanel Orientation="Vertical" x:Name="stackPanel" >
                         <Leadtools_Windows_Controls:RasterImageViewer x:Name="viewerControl" SizeMode="Normal"  Width="500" Height="500"></Leadtools_Windows_Controls:RasterImageViewer>
                         <Button Name="myButton" Content="Load" FontSize="30" Click="Button_Click"></Button>
                         <RadioButton x:Name="_rbRunMode" Content="Run Mode" Checked="AnnotationMode_Changed" HorizontalAlignment="Center" FontSize="20"></RadioButton>
                         <RadioButton x:Name="_rbDesignMode" Content="Design Mode" Checked="AnnotationMode_Changed" HorizontalAlignment="Center" FontSize="20"></RadioButton>
                      </StackPanel>
                   </Grid>
                </UserControl>
                 
                
    
  5. Switch to Page.xaml code view (right-click Page.xaml in the solution explorer then select View Code) and add the following lines at the beginning of the file:

    [Visual Basic]

                Imports Leadtools.Windows.Annotations
                                                    
    

    [C#]

                using Leadtools.Windows.Annotations;
                                                            
    

  6. Switch to Page.xaml code view (right-click Page.xaml in the solution explorer then select View Code) and add the following class level variable:

    [Visual Basic]

                Dim _automation As AnnAutomation
                                                    
    

    [C#]

                AnnAutomation _automation;
                                                            
    

  7. Update the MainPage() function as shown below:

    [Visual Basic]

                Public Sub New()
                  InitializeComponent()
                  RasterSupport.SetLicense(RasterSupportType.Document, "Your Document unlock key here")
                  Dim manager As AnnAutomationManager = New AnnAutomationManager()
                  manager.CreateDefaultObjects()
                  manager.CreateToolBar()
                  stackPanel.Children.Insert(0, manager.ToolBar)
                  manager.ToolBar.Orientation = Orientation.Horizontal
                  manager.ToolBar.HorizontalAlignment = HorizontalAlignment.Center
                  _automation = New AnnAutomation(manager, viewerControl)
                  _rbDesignMode.IsChecked = True
                End Sub
                
    

    [C#]

                public MainPage()
                {
                  InitializeComponent();
                  RasterSupport.SetLicense(RasterSupportType.Document, "Your Document unlock key here");
                  AnnAutomationManager manager = new AnnAutomationManager();
                  manager.CreateDefaultObjects();
                  manager.CreateToolBar();
                  stackPanel.Children.Insert(0, manager.ToolBar);
                  manager.ToolBar.Orientation = Orientation.Horizontal;
                  manager.ToolBar.HorizontalAlignment = HorizontalAlignment.Center;
                  _automation = new AnnAutomation(manager, viewerControl);
                  _rbDesignMode.IsChecked = true;
                }
                
    

  8. Add the following class function:

    [Visual Basic]

                Private Sub AnnotationMode_Changed(ByVal sender As Object, ByVal e As RoutedEventArgs)
                  If CBool(_rbDesignMode.IsChecked) Then
                     _automation.Manager.UserMode = AnnUserMode.Design
                  Else
                     _automation.Manager.UserMode = AnnUserMode.Run
                  End If
                End Sub
                
    

    [C#]

                private void AnnotationMode_Changed(object sender, RoutedEventArgs e)
                {
                  _automation.Manager.UserMode = (bool)_rbDesignMode.IsChecked ? AnnUserMode.Design : AnnUserMode.Run;
                }
                
    
  9. Build, and Run the program to test it.

    Click the "Load" button and select a valid image.

    NOTE: if you encounter and "Invalid File Format" or "Feature Not Supported" exception, please refer to the topic Invalid File Format/Feature Not Supported.

    Use the toolbar above the viewer to select annotations. The radio buttons will allow you to switch between design and run mode.

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.