PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Visual Studio 2008/VBSL3Animation/MyEllipse.xaml.vb

#
Visual Basic | 89 lines | 47 code | 14 blank | 28 comment | 0 complexity | a17978f4fa5e006c00d065383a7ba9f2 MD5 | raw file
 1'***************************** Module Header ******************************\
 2'* Module Name:  MyEllipse.xaml.vb
 3'* Project:      VBSL3Animation
 4'* Copyright (c) Microsoft Corporation.
 5'* 
 6'* This module shows how to write a UserControl that basically wraps EllipseGeometry
 7'* to "expose" its Center property.
 8'* 
 9'* This source is subject to the Microsoft Public License.
10'* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11'* All other rights reserved.
12'* 
13'* History:
14'* * 9/8/2009 05:00 PM Allen Chen Created
15'\**************************************************************************
16
17Public Delegate Sub EllipseCenterChangedEventHandler(ByVal sender As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
18
19Partial Public Class MyEllipse
20    Inherits UserControl
21
22    Public Shared ReadOnly EllipseCenterProperty As DependencyProperty = DependencyProperty.Register("EllipseCenter", GetType(Point), GetType(MyEllipse), New PropertyMetadata(New PropertyChangedCallback(AddressOf MyHandler)))
23    Private _mydelegate As EllipseCenterChangedEventHandler
24
25    Public Custom Event EllipseCenterChanged As EllipseCenterChangedEventHandler
26        AddHandler(ByVal value As EllipseCenterChangedEventHandler)
27            If _mydelegate Is Nothing Then
28                _mydelegate = value
29            Else
30                System.Delegate.Combine(_mydelegate, value)
31            End If
32        End AddHandler
33        RemoveHandler(ByVal value As EllipseCenterChangedEventHandler)
34
35            System.Delegate.Remove(_mydelegate, value)
36        End RemoveHandler
37        RaiseEvent(ByVal sender As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
38        End RaiseEvent
39    End Event
40
41
42    Public Property EllipseCenter() As Point
43        Get
44            Return CType(GetValue(EllipseCenterProperty), Point)
45        End Get
46        Set(ByVal value As Point)
47            SetValue(EllipseCenterProperty, value)
48        End Set
49
50    End Property
51
52
53    Public Sub New()
54
55        InitializeComponent()
56        EllipseCenter = Me.MyAnimatedEllipseGeometry.Center
57    End Sub
58
59    ''' <summary>
60    ''' This is a callback method that triggers OnEllipseCenterChanged method of
61    ''' the MyEllipse object whose EllipseCenter property got changed.
62    ''' </summary>
63    ''' <param name="obj"></param>
64    ''' <param name="e"></param>
65    Shared Sub MyHandler(ByVal obj As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
66
67        Dim ellipse As MyEllipse = TryCast(obj, MyEllipse)
68        If Not ellipse Is Nothing Then
69            ellipse.OnEllipseCenterChanged(obj, e)
70        End If
71    End Sub
72
73    ''' <summary>
74    ''' This method is triggered by the callback method of EllipseCenterProperty
75    ''' property. It updates the Center property of the EllipseGeometry object to
76    ''' update UI,then it fires EllipseCenterChanged event.
77    ''' </summary>
78    ''' <param name="obj"></param>
79    ''' <param name="e"></param>
80    Private Sub OnEllipseCenterChanged(ByVal obj As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
81        Dim ellipse As MyEllipse = TryCast(obj, MyEllipse)
82        If Not ellipse Is Nothing Then
83            ellipse.MyAnimatedEllipseGeometry.Center = ellipse.EllipseCenter
84        End If
85        If Not _mydelegate Is Nothing Then
86            _mydelegate(obj, e)
87        End If
88    End Sub
89End Class