LEADTOOLS WPF and Silverlight (Leadtools.Windows.Controls assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.30
ImageBox Class
See Also  Members  
Leadtools.Windows.Controls Namespace : ImageBox Class



Represents a control that displays a WPF/Silverlight System.Windows.Media.ImageSource. Supported in Silverlight, Windows Phone 7

Object Model

ImageBox Class

Syntax

Visual Basic (Declaration) 
Public Class ImageBox 
   Inherits System.Windows.Controls.Panel
   Implements ISupportInitializeIFrameworkInputElementIInputElementIAddChildIAnimatable 
Visual Basic (Usage)Copy Code
Dim instance As ImageBox

Example

Visual BasicCopy Code
Private Class MyWindow1 : Inherits Window
         Private theImage As ImageBox
         Public Sub New()
             ' Create the  viewer
             theImage = New ImageBox()

             ' Create Dock Panel

             Dim panel As DockPanel = New DockPanel()
             Content = panel

             DockPanel.SetDock(theImage, Dock.Bottom)

             theImage.HorizontalAlignment = HorizontalAlignment.Center
             theImage.VerticalAlignment = VerticalAlignment.Bottom
             theImage.UseDpi = True
             theImage.ScreenDpiX = 96
             theImage.ScreenDpiY = 96

             panel.Children.Add(theImage)

             ' load an image into the viewer
             theImage.Source = New BitmapImage(New Uri(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg")))

             Title = String.Format("Size mode = {0}, click to change", theImage.SizeMode)

             AddHandler theImage.MouseDown, AddressOf theImage_MouseClick
         End Sub

         Private Sub theImage_MouseClick(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
             Select Case theImage.SizeMode
                 Case SizeMode.Normal
                     theImage.SizeMode = SizeMode.Stretch

                 Case SizeMode.Stretch
                     theImage.SizeMode = SizeMode.Fit

                 Case SizeMode.Fit
                     theImage.SizeMode = SizeMode.FitAlways

                 Case SizeMode.FitAlways
                     theImage.SizeMode = SizeMode.FitWidth

                 Case SizeMode.FitWidth
                     theImage.SizeMode = SizeMode.Normal
             End Select

             Title = String.Format("Size mode = {0}, double click to change", theImage.SizeMode)

         End Sub
     End Class

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
class MyWindow1 : Window
   {
      ImageBox theImage;
      public MyWindow1()
      {
         // Create the  viewer
         theImage = new ImageBox();

         // Create Dock Panel

         DockPanel panel = new DockPanel();
         Content = panel;

         DockPanel.SetDock(theImage, Dock.Bottom);

         theImage.HorizontalAlignment = HorizontalAlignment.Center;
         theImage.VerticalAlignment= VerticalAlignment.Bottom;
         theImage.UseDpi = true;
         theImage.ScreenDpiX = 96;
         theImage.ScreenDpiY = 96;

         panel.Children.Add(theImage);

         // load an image into the viewer
         theImage.Source = new BitmapImage(new Uri(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg")));

         Title = string.Format("Size mode = {0}, click to change", theImage.SizeMode);

         theImage.MouseDown += new MouseButtonEventHandler(theImage_MouseClick);
      }

      void theImage_MouseClick(object sender, MouseButtonEventArgs e)
      {
         switch(theImage.SizeMode)
         {
            case SizeMode.Normal:
               theImage.SizeMode = SizeMode.Stretch;
               break;

            case SizeMode.Stretch:
               theImage.SizeMode = SizeMode.Fit;
               break;

            case SizeMode.Fit:
               theImage.SizeMode = SizeMode.FitAlways;
               break;

            case SizeMode.FitAlways:
               theImage.SizeMode = SizeMode.FitWidth;
               break;

            case SizeMode.FitWidth:
               theImage.SizeMode = SizeMode.Normal;
               break;
         }

         Title = string.Format("Size mode = {0}, double click to change", theImage.SizeMode);

      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
class MyWindow1 : ChildWindow
{
   ImageBox theImage;
   public MyWindow1()
   {
      // Create the  viewer
      theImage = new ImageBox();

      // Create Dock Panel

      StackPanel panel = new StackPanel();
      Content = panel;

      theImage.HorizontalAlignment = HorizontalAlignment.Center;
      theImage.VerticalAlignment= VerticalAlignment.Bottom;
      theImage.UseDpi = true;
      theImage.ScreenDpiX = 96;
      theImage.ScreenDpiY = 96;

      panel.Children.Add(theImage);

      // load an image into the viewer
      theImage.Source = new BitmapImage(new Uri(LeadtoolsExamples.Common.ImagesPath.Path + "cannon.jpg"));

      Title = string.Format("Size mode = {0}, click to change", theImage.SizeMode);

      theImage.MouseLeftButtonDown +=new MouseButtonEventHandler(theImage_MouseLeftButtonDown);
   }

   void theImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
   {
      switch (theImage.SizeMode)
      {
         case SizeMode.Normal:
            theImage.SizeMode = SizeMode.Stretch;
            break;

         case SizeMode.Stretch:
            theImage.SizeMode = SizeMode.Fit;
            break;

         case SizeMode.Fit:
            theImage.SizeMode = SizeMode.FitAlways;
            break;

         case SizeMode.FitAlways:
            theImage.SizeMode = SizeMode.FitWidth;
            break;

         case SizeMode.FitWidth:
            theImage.SizeMode = SizeMode.Normal;
            break;
      }

      Title = string.Format("Size mode = {0}, double click to change", theImage.SizeMode);
   }
}
SilverlightVBCopy Code
Private Class MyWindow1 : Inherits ChildWindow
   Private theImage As ImageBox
   Public Sub New()
      ' Create the  viewer
      theImage = New ImageBox()

      ' Create Dock Panel

      Dim panel As StackPanel = New StackPanel()
      Content = panel

      theImage.HorizontalAlignment = HorizontalAlignment.Center
      theImage.VerticalAlignment= VerticalAlignment.Bottom
      theImage.UseDpi = True
      theImage.ScreenDpiX = 96
      theImage.ScreenDpiY = 96

      panel.Children.Add(theImage)

      ' load an image into the viewer
      theImage.Source = New BitmapImage(New Uri(LeadtoolsExamples.Common.ImagesPath.Path & "cannon.jpg"))

      Title = String.Format("Size mode = {0}, click to change", theImage.SizeMode)

      AddHandler theImage.MouseLeftButtonDown, AddressOf theImage_MouseLeftButtonDown
   End Sub

   Private Sub theImage_MouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
      Select Case theImage.SizeMode
         Case SizeMode.Normal
            theImage.SizeMode = SizeMode.Stretch

         Case SizeMode.Stretch
            theImage.SizeMode = SizeMode.Fit

         Case SizeMode.Fit
            theImage.SizeMode = SizeMode.FitAlways

         Case SizeMode.FitAlways
            theImage.SizeMode = SizeMode.FitWidth

         Case SizeMode.FitWidth
            theImage.SizeMode = SizeMode.Normal
      End Select

      Title = String.Format("Size mode = {0}, double click to change", theImage.SizeMode)
   End Sub
End Class
XAMLCopy Code
<Window x:Class="WPFSamples.ImageBox" Height="600" Width="800" 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">
  <DockPanel>
    <Leadtools_Windows_Controls:ImageBox Name="theImage" Source="file:///c:\users\Public\Documents\LEADTOOLS Images\cannon.jpg" DockPanel.Dock="Bottom" HorizontalAlignment="Center" VerticalAlignment="Bottom" SizeMode="Fit" UseDpi="true"></Leadtools_Windows_Controls:ImageBox>
  </DockPanel>
  <Window.Title>
        "Apply a effect"
      </Window.Title>
</Window>

Remarks

The ImageBox class enables you to display a WPF/Silverlight System.Windows.Media.ImageSource or one of its derived classes. To display a LEADTOOLS Leadtools.RasterImage, use the RasterImageBox control.

This control is suitable when you want to display a static image, i.e. an image that does not require scrolling or any other interactive operations in your WPF/Silverlight application. If such interactive operations are required, use the ImageViewer or RasterImageViewer controls.

Until the image content is loaded, the System.Windows.FrameworkElement.ActualWidth and System.Windows.FrameworkElement.ActualHeight of the control will report as zero, because the image content is used to determine the final size and location of the control.

For a fixed size control, the System.Windows.FrameworkElement.Width and/or System.Windows.FrameworkElement.Height properties can be set. However, to preserve the media's aspect ratio, set the System.Windows.FrameworkElement.Width or System.Windows.FrameworkElement.Height properties but not both.

The ImageBox controls supports the following functionality:

Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Media.Visual
            System.Windows.UIElement
               System.Windows.FrameworkElement
                  System.Windows.Controls.Panel
                     Leadtools.Windows.Controls.ImageBox
                        Leadtools.Windows.Controls.RasterImageBox

Requirements

Target Platforms: Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also