LEADTOOLS WPF and Silverlight Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.22
Working with Automated Annotations in Windows Phone 7

Take the following steps to start a project and to add some code that demonstrates the LEADTOOLS annotation features in Windows Phone 7.

  1. Start Visual Studio .NET 2010 or higher
  2. Start with the project that you created in Loading and displaying an image in Windows Phone 7.
  3. In the "Solution Explorer" window, right-click on the "References" folder for the Windows Phone 7 project and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, browse to the "\LEAD Technologies\LEADTOOLS 17\Bin\SilverlightPhone" folder and select the following DLLs:

    • Leadtools.Windows.Annotations.dll
    • System.Windows.Controls.dll
    Click the Select button and then press the OK button to add the above DLLs to the application.
  4. Open the MainPage.xaml file and copy the below xaml code into the editor:

    [XAML]

                <phone:PhoneApplicationPage 
                    x:Class="LoadingAndDisplayingAnImageWindowsPhone.MainPage"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
                    FontFamily="{StaticResource PhoneFontFamilyNormal}"
                    FontSize="{StaticResource PhoneFontSizeNormal}"
                    Foreground="{StaticResource PhoneForegroundBrush}"
                    SupportedOrientations="Portrait" Orientation="Portrait"
                    shell:SystemTray.IsVisible="True" xmlns:my="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls" Loaded="PhoneApplicationPage_Loaded">
                
                   <!--LayoutRoot is the root grid where all page content is placed-->
                   <Grid x:Name="LayoutRoot" Background="Transparent">
                      <StackPanel Orientation="Vertical">
                         <my:RasterImageViewer Name="rasterImageViewer" Height="480" Width="480" SizeMode="Fit" InteractiveMode="None"/>
                         <Button Name="_btnLoadFromLibrary" Click="_btnLoadFromLibrary_Click" Content="Load From Library"></Button>
                         <Button Name="_btnLoadFromURL" Click="_btnLoadFromURL_Click" Content="Load From URL"></Button>
                         <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                            <Button Name="_btnDrawRectangle" Content="Draw Rectangle" Click="_btnDrawRectangle_Click" Width="230"></Button>
                            <Button Name="_btnDrawEllipse" Content="Draw Ellipse" Click="_btnDrawEllipse_Click" Width="230"></Button>
                         </StackPanel>
                         <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                            <Button Name="_btnDrawHilite" Content="Draw Hilite" Click="_btnDrawHilite_Click" Width="230"></Button>
                            <Button Name="_btnDrawFreehand" Content="Draw Freehand" Click="_btnDrawFreehand_Click" Width="230"></Button>
                         </StackPanel>
                      </StackPanel>
                   </Grid>
                </phone:PhoneApplicationPage>
                 
    
  5. Switch to MainPage.xaml code view (right-click Page.xaml in the solution explorer then select View Code) and add the following line at the beginning of the file:

    [C#]

                 using Leadtools.Windows.Annotations;
                 
    

  6. Add the following class level variable:

    [C#]

                 AnnAutomationManager annAutomationManager = null;
                 AnnAutomation annAutomation = null;
                 
    

  7. Add the following class function:

    [C#]

     
                      private void InitAnnotationAutomation()
                      {
                         try
                         {
                            // create and setup the automation manager
                            annAutomationManager = new AnnAutomationManager();
                            // Instruct the manager to create the default (all) automation objects.
                            annAutomationManager.CreateDefaultObjects();
                            annAutomationManager.UserMode = AnnUserMode.Design;
                            // setup the automation (will create the container as well)
                            annAutomation = new AnnAutomation(annAutomationManager, rasterImageViewer);
                            // setup this automation as the active one
                            annAutomation.Active = true;
                         }
                         catch (Exception ex)
                         {
                            MessageBox.Show(ex.Message);
                         }
                      }
                  
                 
    

  8. Modify the PhoneApplicationPage_Loaded() function as shown below:

    [C#]

                      private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
                      {
                         codecs = new RasterCodecs();
                         codecs.LoadAsyncCompleted += new EventHandler<CodecsLoadAsyncCompletedEventArgs>(codecs_LoadAsyncCompleted);
                         InitAnnotationAutomation();
                         rasterImageViewer.AnnotationMode = true;
                      }
                 
    

  9. Build, and Run the program to test it.

    Click the "Load From URL" button to load an image from a URL.

    Click the "Load From Library" button to load an image from the Windows Phone photo library.

    Click the various buttons to draw annotations.

    NOTE: This tutorial demonstrates how to implement basic annotation features in LEADTOOLS. It does not include all annotation features. For a complete demo, see the "AutomationDemo" located in the LEADTOOLS 17\Examples\SilverlightPhone\CS directory.

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