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



e
A RoutedPropertyChangedEventArgs that contains the event data.
e
A RoutedPropertyChangedEventArgs that contains the event data.
Raises the SourceChanged event.

Syntax

Visual Basic (Declaration) 
Protected Overridable Sub OnSourceChanged( _
   ByVal e As RoutedPropertyChangedEventArgs(Of ImageViewer) _
) 
Visual Basic (Usage)Copy Code
Dim instance As ImagePanViewer
Dim e As RoutedPropertyChangedEventArgs(Of ImageViewer)
 
instance.OnSourceChanged(e)
C# 
protected virtual void OnSourceChanged( 
   RoutedPropertyChangedEventArgs<ImageViewer> e
)
C++/CLI 
protected:
virtual void OnSourceChanged( 
   RoutedPropertyChangedEventArgs<ImageViewer^>^ e
) 

Parameters

e
A RoutedPropertyChangedEventArgs that contains the event data.

Example

Visual BasicCopy Code
Public Sub ImagePanViewer_SourceChanged(ByVal panViewer As ImagePanViewer)
    ' set up the event handlers
    AddHandler panViewer.StrokeChanged, AddressOf panViewer_StrokeChanged
    AddHandler panViewer.SourceChanged, AddressOf panViewer_SourceChanged
    AddHandler panViewer.InnerBrushChanged, AddressOf panViewer_InnerBrushChanged
    AddHandler panViewer.OuterBrushChanged, AddressOf panViewer_OuterBrushChanged
    AddHandler panViewer.PositionChanged, AddressOf panViewer_PositionChanged
    Dim viewerOld As ImageViewer = panViewer.Source
    ' fires the SourceChanged event twice
    panViewer.Source = Nothing
    panViewer.Source = viewerOld

    ' change some properties
    panViewer.Stroke = Brushes.Black
    panViewer.StrokeThickness = 2

    panViewer.Position = New Point(20, 20)
End Sub

Private Sub panViewer_PositionChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Point))
    Dim panViewer As ImagePanViewer = CType(sender, ImagePanViewer)
    If Not panViewer Is Nothing Then
        Console.WriteLine("Position Changed to " & panViewer.Position.ToString())
    End If
End Sub

Private Sub panViewer_OuterBrushChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Brush))
    Dim panViewer As ImagePanViewer = CType(sender, ImagePanViewer)
    If Not panViewer Is Nothing Then
        Console.WriteLine("Inner Brush Changed to " & panViewer.OuterBrush.ToString() & "Color")
    End If
End Sub

Private Sub panViewer_InnerBrushChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Brush))
    Dim panViewer As ImagePanViewer = CType(sender, ImagePanViewer)
    If Not panViewer Is Nothing Then
        Console.WriteLine("Inner Brush Changed to " & panViewer.InnerBrush.ToString() & "Color")
    End If
End Sub

Private Sub panViewer_StrokeChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Brush))
    Dim panViewer As ImagePanViewer = CType(sender, ImagePanViewer)
    If Not panViewer Is Nothing Then
        Console.WriteLine("Rectangle Stroke Changed to " & panViewer.StrokeThickness.ToString() & "Thickness and to" & panViewer.Stroke.ToString() & "Color")
    End If
End Sub

Private Sub panViewer_SourceChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of ImageViewer))
    Dim panViewer As ImagePanViewer = CType(sender, ImagePanViewer)
    If Not panViewer Is Nothing Then
        If panViewer.Source Is Nothing Then
            Console.WriteLine("There is no Viewer control associated with the ImagePanViewer Control")
        Else
            Console.WriteLine("A Viewer is now associated with the ImagePanViewer Control")
        End If
    End If
End Sub
C#Copy Code
public void ImagePanViewer_SourceChanged(ImagePanViewer panViewer)
{
   // set up the event handlers
   panViewer.StrokeChanged += new RoutedPropertyChangedEventHandler<Brush>(panViewer_StrokeChanged);
   panViewer.SourceChanged += new RoutedPropertyChangedEventHandler<ImageViewer>(panViewer_SourceChanged);
   panViewer.InnerBrushChanged +=new RoutedPropertyChangedEventHandler<Brush>(panViewer_InnerBrushChanged);
   panViewer.OuterBrushChanged +=new RoutedPropertyChangedEventHandler<Brush>(panViewer_OuterBrushChanged);
   panViewer.PositionChanged += new RoutedPropertyChangedEventHandler<Point>(panViewer_PositionChanged);
   ImageViewer viewerOld = panViewer.Source;
   // fires the SourceChanged event twice
   panViewer.Source = null;
   panViewer.Source = viewerOld;

   // change some properties
   panViewer.Stroke = Brushes.Black;
   panViewer.StrokeThickness = 2;

   panViewer.Position = new Point(20, 20);
}

void panViewer_PositionChanged(object sender, RoutedPropertyChangedEventArgs<Point> e)
{
   ImagePanViewer panViewer = (ImagePanViewer)sender;
   if (panViewer != null)
      Console.WriteLine("Position Changed to " + panViewer.Position.ToString());
}

void panViewer_OuterBrushChanged(object sender, RoutedPropertyChangedEventArgs<Brush> e)
{
   ImagePanViewer panViewer = (ImagePanViewer)sender;
   if (panViewer != null)
      Console.WriteLine("Inner Brush Changed to " + panViewer.OuterBrush.ToString() + "Color");
}

void panViewer_InnerBrushChanged(object sender, RoutedPropertyChangedEventArgs<Brush> e)
{
   ImagePanViewer panViewer = (ImagePanViewer)sender;
   if (panViewer != null)
      Console.WriteLine("Inner Brush Changed to " + panViewer.InnerBrush.ToString() + "Color");
}

private void panViewer_StrokeChanged(object sender, RoutedPropertyChangedEventArgs<Brush> e)
{
   ImagePanViewer panViewer = (ImagePanViewer)sender;
   if(panViewer != null)
      Console.WriteLine("Rectangle Stroke Changed to " + panViewer.StrokeThickness.ToString() +"Thickness and to"  + panViewer.Stroke.ToString()+ "Color");
}

private void panViewer_SourceChanged(object sender, RoutedPropertyChangedEventArgs<ImageViewer> e)
{
   ImagePanViewer panViewer = (ImagePanViewer)sender;
   if(panViewer != null)
   {
      if(panViewer.Source == null)
         Console.WriteLine("There is no Viewer control associated with the ImagePanViewer Control");
      else
         Console.WriteLine("A Viewer is now associated with the ImagePanViewer Control");
   }
}
SilverlightCSharpCopy Code
public void ImagePanViewer_SourceChanged(ImagePanViewer panViewer)
{
   // set up the event handlers
   panViewer.StrokeChanged += new RoutedPropertyChangedEventHandler<Brush>(panViewer_StrokeChanged);
   panViewer.SourceChanged += new RoutedPropertyChangedEventHandler<ImageViewer>(panViewer_SourceChanged);
   panViewer.InnerBrushChanged += new RoutedPropertyChangedEventHandler<Brush>(panViewer_InnerBrushChanged);
   panViewer.OuterBrushChanged += new RoutedPropertyChangedEventHandler<Brush>(panViewer_OuterBrushChanged);
   panViewer.PositionChanged += new RoutedPropertyChangedEventHandler<Point>(panViewer_PositionChanged);
   ImageViewer viewerOld = panViewer.Source;
   // fires the SourceChanged event twice
   panViewer.Source = null;
   panViewer.Source = viewerOld;

   // change some properties
   panViewer.Stroke = new SolidColorBrush(Colors.Black);
   panViewer.StrokeThickness = 2;

   panViewer.Position = new Point(20, 20);
}

void panViewer_PositionChanged(object sender, RoutedPropertyChangedEventArgs<Point> e)
{
   ImagePanViewer panViewer = (ImagePanViewer)sender;
   if (panViewer != null)
      Console.WriteLine("Position Changed to " + panViewer.Position.ToString());
}

void panViewer_OuterBrushChanged(object sender, RoutedPropertyChangedEventArgs<Brush> e)
{
   ImagePanViewer panViewer = (ImagePanViewer)sender;
   if (panViewer != null)
      Console.WriteLine("Inner Brush Changed to " + panViewer.OuterBrush.ToString() + "Color");
}

void panViewer_InnerBrushChanged(object sender, RoutedPropertyChangedEventArgs<Brush> e)
{
   ImagePanViewer panViewer = (ImagePanViewer)sender;
   if (panViewer != null)
      Console.WriteLine("Inner Brush Changed to " + panViewer.InnerBrush.ToString() + "Color");
}

private void panViewer_StrokeChanged(object sender, RoutedPropertyChangedEventArgs<Brush> e)
{
   ImagePanViewer panViewer = (ImagePanViewer)sender;
   if (panViewer != null)
      Console.WriteLine("Rectangle Stroke Changed to " + panViewer.StrokeThickness.ToString() + "Thickness and to" + panViewer.Stroke.ToString() + "Color");
}

private void panViewer_SourceChanged(object sender, RoutedPropertyChangedEventArgs<ImageViewer> e)
{
   ImagePanViewer panViewer = (ImagePanViewer)sender;
   if (panViewer != null)
   {
      if (panViewer.Source == null)
         Console.WriteLine("There is no Viewer control associated with the ImagePanViewer Control");
      else
         Console.WriteLine("A Viewer is now associated with the ImagePanViewer Control");
   }
}
SilverlightVBCopy Code
Public Sub ImagePanViewer_SourceChanged(ByVal panViewer As ImagePanViewer)
   ' set up the event handlers
   AddHandler panViewer.StrokeChanged, AddressOf panViewer_StrokeChanged
   AddHandler panViewer.SourceChanged, AddressOf panViewer_SourceChanged
   AddHandler panViewer.InnerBrushChanged, AddressOf panViewer_InnerBrushChanged
   AddHandler panViewer.OuterBrushChanged, AddressOf panViewer_OuterBrushChanged
   AddHandler panViewer.PositionChanged, AddressOf panViewer_PositionChanged
   Dim viewerOld As ImageViewer = panViewer.Source
   ' fires the SourceChanged event twice
   panViewer.Source = Nothing
   panViewer.Source = viewerOld

   ' change some properties
   panViewer.Stroke = New SolidColorBrush(Colors.Black)
   panViewer.StrokeThickness = 2

   panViewer.Position = New Point(20, 20)
End Sub

Private Sub panViewer_PositionChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Point))
   Dim panViewer As ImagePanViewer = CType(sender, ImagePanViewer)
   If Not panViewer Is Nothing Then
      Console.WriteLine("Position Changed to " & panViewer.Position.ToString())
   End If
End Sub

Private Sub panViewer_OuterBrushChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Brush))
   Dim panViewer As ImagePanViewer = CType(sender, ImagePanViewer)
   If Not panViewer Is Nothing Then
      Console.WriteLine("Inner Brush Changed to " & panViewer.OuterBrush.ToString() & "Color")
   End If
End Sub

Private Sub panViewer_InnerBrushChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Brush))
   Dim panViewer As ImagePanViewer = CType(sender, ImagePanViewer)
   If Not panViewer Is Nothing Then
      Console.WriteLine("Inner Brush Changed to " & panViewer.InnerBrush.ToString() & "Color")
   End If
End Sub

Private Sub panViewer_StrokeChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Brush))
   Dim panViewer As ImagePanViewer = CType(sender, ImagePanViewer)
   If Not panViewer Is Nothing Then
      Console.WriteLine("Rectangle Stroke Changed to " & panViewer.StrokeThickness.ToString() & "Thickness and to" & panViewer.Stroke.ToString() & "Color")
   End If
End Sub

Private Sub panViewer_SourceChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of ImageViewer))
   Dim panViewer As ImagePanViewer = CType(sender, ImagePanViewer)
   If Not panViewer Is Nothing Then
      If panViewer.Source Is Nothing Then
         Console.WriteLine("There is no Viewer control associated with the ImagePanViewer Control")
      Else
         Console.WriteLine("A Viewer is now associated with the ImagePanViewer Control")
      End If
   End If
End Sub

Remarks

Raising an event invokes the event handler through a delegate.

The OnSourceChanged method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors: When overriding OnSourceChanged in a derived class, be sure to call the base class's OnSourceChanged method so that registered delegates receive the event.

Requirements

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

See Also