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



The AnnObjectCollection Class supports WPF/Silverlight.

The AnnObjectCollection Class is available in LEADTOOLS Document and Medical Imaging toolkits.

Represents an ordered collection of AnnObject. Supported in Silverlight, Windows Phone 7

Object Model

AnnObjectCollection ClassAnnObject Class

Syntax

Example

Visual BasicCopy Code
Public Sub AnnObjectCollectionExample(ByVal container As AnnContainer)
   AddHandler container.ObjectAdded, AddressOf container_ObjectAdded
   AddHandler container.ObjectRemoved, AddressOf container_ObjectRemoved
   ' add a few objects
   Dim lineObj As AnnLineObject = New AnnLineObject()
   lineObj.Start = New Point(100, 100)
   lineObj.End = New Point(200, 200)
   lineObj.Stroke = Colors.Blue
   lineObj.StrokeThickness = 2.0
   lineObj.Header = "Object 1"

   Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
   rectObj.Rect = New Rect(200, 200, 100, 100)
   rectObj.Stroke = Colors.Blue
   rectObj.StrokeThickness = 2.0
   rectObj.Fill = Colors.Transparent
   rectObj.Header = "Object 2"

   Dim ellipseObj As AnnEllipseObject = New AnnEllipseObject()
   ellipseObj.Rect = New Rect(200, 200, 150, 100)
   ellipseObj.Stroke = Colors.Yellow
   ellipseObj.StrokeThickness = 2.0
   ellipseObj.Fill = Colors.Green
   ellipseObj.Header = "Object 3"

   container.Children.Add(lineObj)
   container.Children.Add(rectObj)
   container.Children.Add(ellipseObj)

   ' insert new Object
   Dim newLineObj As AnnLineObject = DirectCast(lineObj.Clone(), AnnLineObject)
   newLineObj.Start = New Point(110, 110)
   newLineObj.End = New Point(210, 210)
   newLineObj.Stroke = Colors.Red
   newLineObj.StrokeThickness = 2.0
   newLineObj.Header = "New Object"

   container.Children.Insert(1, newLineObj)

   ' check if collection contains this new item 
   System.Diagnostics.Debug.Assert(container.Children.Contains(newLineObj))

   ' remove this new item 
   container.Children.Remove(newLineObj)
   System.Diagnostics.Debug.Assert((Not container.Children.Contains(newLineObj)))

   ' remove the last item 
   container.Children.RemoveAt(container.Children.Count - 1)
   System.Diagnostics.Debug.Assert(container.Children.Count = 2)

   ' send the first item to the end of the collection 
   container.Children.SendToBack(lineObj, True)
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) = container.Children.Count - 1)

   ' bring it back to the front 
   container.Children.BringToFront(lineObj, True)
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) = 0)

   ' clean the collection 
   container.Children.Clear()
   System.Diagnostics.Debug.Assert(container.Children.Count = 0)
End Sub

Private Sub container_ObjectAdded(ByVal sender As Object, ByVal e As AnnObjectCollectionEventArgs)
   Console.WriteLine("The Object ((" & e.Object.Header & ")) Has been added to the collection")
End Sub

Private Sub container_ObjectRemoved(ByVal sender As System.Object, ByVal e As AnnObjectCollectionEventArgs)
   Console.WriteLine("The Object ((" & e.Object.Header & ")) Has been removed from the collection")
End Sub
C#Copy Code
public void AnnObjectCollectionExample(AnnContainer container)
{
   container.ObjectAdded += new EventHandler<AnnObjectCollectionEventArgs>(container_ObjectAdded);
   container.ObjectRemoved += new EventHandler<AnnObjectCollectionEventArgs>(container_ObjectRemoved);
   // add a few objects
   AnnLineObject lineObj = new AnnLineObject();
   lineObj.Start = new Point(100, 100);
   lineObj.End = new Point(200, 200);
   lineObj.Stroke = Colors.Blue;
   lineObj.StrokeThickness = 2.0;
   lineObj.Header = "Object 1";

   AnnRectangleObject rectObj = new AnnRectangleObject();
   rectObj.Rect = new Rect(200, 200, 100, 100);
   rectObj.Stroke = Colors.Blue;
   rectObj.Fill = Colors.Transparent;
   rectObj.StrokeThickness = 2.0;
   rectObj.Header = "Object 2";

   AnnEllipseObject ellipseObj = new AnnEllipseObject();
   ellipseObj.Rect = new Rect(200, 200, 150, 100);
   ellipseObj.Stroke = Colors.Yellow;
   ellipseObj.Fill = Colors.Green;
   ellipseObj.StrokeThickness = 2.0;
   ellipseObj.Header = "Object 3";

   container.Children.Add(lineObj);
   container.Children.Add(rectObj);
   container.Children.Add(ellipseObj);

   // insert new Object
   AnnLineObject newLineObj = lineObj.Clone() as AnnLineObject;
   newLineObj.Start = new Point(110, 110);
   newLineObj.End = new Point(210, 210);
   newLineObj.Stroke = Colors.Red;
   newLineObj.StrokeThickness = 2.0;
   newLineObj.Header = "New Object";

   container.Children.Insert(1, newLineObj);

   // check if collection contains this new item 
   System.Diagnostics.Debug.Assert(container.Children.Contains(newLineObj));

   // remove this new item 
   container.Children.Remove(newLineObj);
   System.Diagnostics.Debug.Assert(!container.Children.Contains(newLineObj));

   // remove the last item 
   container.Children.RemoveAt(container.Children.Count - 1);
   System.Diagnostics.Debug.Assert(container.Children.Count == 2);

   // send the first item to the end of the collection 
   container.Children.SendToBack(lineObj, true);
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) == container.Children.Count - 1);

   // bring it back to the front 
   container.Children.BringToFront(lineObj, true);
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) == 0);

   // clean the collection 
   container.Children.Clear();
   System.Diagnostics.Debug.Assert(container.Children.Count == 0);
}

private void container_ObjectAdded(object sender, AnnObjectCollectionEventArgs e)
{
   Console.WriteLine("The Object ((" + e.Object.Header + ")) Has been added to the collection");
}

private void container_ObjectRemoved(System.Object sender, AnnObjectCollectionEventArgs e)
{
   Console.WriteLine("The Object ((" + e.Object.Header + ")) Has been removed from the collection");
}
SilverlightCSharpCopy Code
public void AnnObjectCollectionExample(AnnContainer container)
{
   container.ObjectAdded += new EventHandler<AnnObjectCollectionEventArgs>(container_ObjectAdded);
   container.ObjectRemoved += new EventHandler<AnnObjectCollectionEventArgs>(container_ObjectRemoved);
   // add a few objects
   AnnLineObject lineObj = new AnnLineObject();
   lineObj.Start = new Point(100, 100);
   lineObj.End = new Point(200, 200);
   lineObj.Stroke = Colors.Blue;
   lineObj.StrokeThickness = 2.0;
   lineObj.Header = "Object 1";

   AnnRectangleObject rectObj = new AnnRectangleObject();
   rectObj.Rect = new Rect(200, 200, 100, 100);
   rectObj.Stroke = Colors.Blue;
   rectObj.Fill = Colors.Transparent;
   rectObj.StrokeThickness = 2.0;
   rectObj.Header = "Object 2";

   AnnEllipseObject ellipseObj = new AnnEllipseObject();
   ellipseObj.Rect = new Rect(200, 200, 150, 100);
   ellipseObj.Stroke = Colors.Yellow;
   ellipseObj.Fill = Colors.Green;
   ellipseObj.StrokeThickness = 2.0;
   ellipseObj.Header = "Object 3";

   container.Children.Add(lineObj);
   container.Children.Add(rectObj);
   container.Children.Add(ellipseObj);

   // insert new Object
   AnnLineObject newLineObj = lineObj.Clone() as AnnLineObject;
   newLineObj.Start = new Point(110, 110);
   newLineObj.End = new Point(210, 210);
   newLineObj.Stroke = Colors.Red;
   newLineObj.StrokeThickness = 2.0;
   newLineObj.Header = "New Object";

   container.Children.Insert(1, newLineObj);

   // check if collection contains this new item 
   System.Diagnostics.Debug.Assert(container.Children.Contains(newLineObj));

   // remove this new item 
   container.Children.Remove(newLineObj);
   System.Diagnostics.Debug.Assert(!container.Children.Contains(newLineObj));

   // remove the last item 
   container.Children.RemoveAt(container.Children.Count - 1);
   System.Diagnostics.Debug.Assert(container.Children.Count == 2);

   // send the first item to the end of the collection 
   container.Children.SendToBack(lineObj, true);
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) == container.Children.Count - 1);

   // bring it back to the front 
   container.Children.BringToFront(lineObj, true);
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) == 0);

   // clean the collection 
   container.Children.Clear();
   System.Diagnostics.Debug.Assert(container.Children.Count == 0);
}

private void container_ObjectAdded(object sender, AnnObjectCollectionEventArgs e)
{
   Console.WriteLine("The Object ((" + e.Object.Header + ")) Has been added to the collection");
}

private void container_ObjectRemoved(System.Object sender, AnnObjectCollectionEventArgs e)
{
   Console.WriteLine("The Object ((" + e.Object.Header + ")) Has been removed from the collection");
}
SilverlightVBCopy Code
Public Sub AnnObjectCollectionExample(ByVal container As AnnContainer)
   AddHandler container.ObjectAdded, AddressOf container_ObjectAdded
   AddHandler container.ObjectRemoved, AddressOf container_ObjectRemoved
   ' add a few objects
   Dim lineObj As AnnLineObject = New AnnLineObject()
   lineObj.Start = New Point(100, 100)
   lineObj.End = New Point(200, 200)
   lineObj.Stroke = Colors.Blue
   lineObj.StrokeThickness = 2.0
   lineObj.Header = "Object 1"

   Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
   rectObj.Rect = New Rect(200, 200, 100, 100)
   rectObj.Stroke = Colors.Blue
   rectObj.Fill = Colors.Transparent
   rectObj.StrokeThickness = 2.0
   rectObj.Header = "Object 2"

   Dim ellipseObj As AnnEllipseObject = New AnnEllipseObject()
   ellipseObj.Rect = New Rect(200, 200, 150, 100)
   ellipseObj.Stroke = Colors.Yellow
   ellipseObj.Fill = Colors.Green
   ellipseObj.StrokeThickness = 2.0
   ellipseObj.Header = "Object 3"

   container.Children.Add(lineObj)
   container.Children.Add(rectObj)
   container.Children.Add(ellipseObj)

   ' insert new Object
   Dim newLineObj As AnnLineObject = TryCast(lineObj.Clone(), AnnLineObject)
   newLineObj.Start = New Point(110, 110)
   newLineObj.End = New Point(210, 210)
   newLineObj.Stroke = Colors.Red
   newLineObj.StrokeThickness = 2.0
   newLineObj.Header = "New Object"

   container.Children.Insert(1, newLineObj)

   ' check if collection contains this new item 
   System.Diagnostics.Debug.Assert(container.Children.Contains(newLineObj))

   ' remove this new item 
   container.Children.Remove(newLineObj)
   System.Diagnostics.Debug.Assert((Not container.Children.Contains(newLineObj)))

   ' remove the last item 
   container.Children.RemoveAt(container.Children.Count - 1)
   System.Diagnostics.Debug.Assert(container.Children.Count = 2)

   ' send the first item to the end of the collection 
   container.Children.SendToBack(lineObj, True)
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) = container.Children.Count - 1)

   ' bring it back to the front 
   container.Children.BringToFront(lineObj, True)
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) = 0)

   ' clean the collection 
   container.Children.Clear()
   System.Diagnostics.Debug.Assert(container.Children.Count = 0)
End Sub

Private Sub container_ObjectAdded(ByVal sender As Object, ByVal e As AnnObjectCollectionEventArgs)
   Console.WriteLine("The Object ((" & e.Object.Header & ")) Has been added to the collection")
End Sub

Private Sub container_ObjectRemoved(ByVal sender As System.Object, ByVal e As AnnObjectCollectionEventArgs)
   Console.WriteLine("The Object ((" & e.Object.Header & ")) Has been removed from the collection")
End Sub

Inheritance Hierarchy

System.Object
   System.Collections.ObjectModel.Collection<T>
      System.Collections.ObjectModel.ObservableCollection<T>
         Leadtools.Windows.Annotations.AnnObjectCollection

Requirements

Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also

AnnObjectCollection requires a Document/Medical product license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features and Unlocking Special LEAD Features.