PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms 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. Public Delegate Sub EllipseCenterChangedEventHandler(ByVal sender As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
  17. Partial Public Class MyEllipse
  18. Inherits UserControl
  19. Public Shared ReadOnly EllipseCenterProperty As DependencyProperty = DependencyProperty.Register("EllipseCenter", GetType(Point), GetType(MyEllipse), New PropertyMetadata(New PropertyChangedCallback(AddressOf MyHandler)))
  20. Private _mydelegate As EllipseCenterChangedEventHandler
  21. Public Custom Event EllipseCenterChanged As EllipseCenterChangedEventHandler
  22. AddHandler(ByVal value As EllipseCenterChangedEventHandler)
  23. If _mydelegate Is Nothing Then
  24. _mydelegate = value
  25. Else
  26. System.Delegate.Combine(_mydelegate, value)
  27. End If
  28. End AddHandler
  29. RemoveHandler(ByVal value As EllipseCenterChangedEventHandler)
  30. System.Delegate.Remove(_mydelegate, value)
  31. End RemoveHandler
  32. RaiseEvent(ByVal sender As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
  33. End RaiseEvent
  34. End Event
  35. Public Property EllipseCenter() As Point
  36. Get
  37. Return CType(GetValue(EllipseCenterProperty), Point)
  38. End Get
  39. Set(ByVal value As Point)
  40. SetValue(EllipseCenterProperty, value)
  41. End Set
  42. End Property
  43. Public Sub New()
  44. InitializeComponent()
  45. EllipseCenter = Me.MyAnimatedEllipseGeometry.Center
  46. End Sub
  47. ''' <summary>
  48. ''' This is a callback method that triggers OnEllipseCenterChanged method of
  49. ''' the MyEllipse object whose EllipseCenter property got changed.
  50. ''' </summary>
  51. ''' <param name="obj"></param>
  52. ''' <param name="e"></param>
  53. Shared Sub MyHandler(ByVal obj As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
  54. Dim ellipse As MyEllipse = TryCast(obj, MyEllipse)
  55. If Not ellipse Is Nothing Then
  56. ellipse.OnEllipseCenterChanged(obj, e)
  57. End If
  58. End Sub
  59. ''' <summary>
  60. ''' This method is triggered by the callback method of EllipseCenterProperty
  61. ''' property. It updates the Center property of the EllipseGeometry object to
  62. ''' update UI,then it fires EllipseCenterChanged event.
  63. ''' </summary>
  64. ''' <param name="obj"></param>
  65. ''' <param name="e"></param>
  66. Private Sub OnEllipseCenterChanged(ByVal obj As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
  67. Dim ellipse As MyEllipse = TryCast(obj, MyEllipse)
  68. If Not ellipse Is Nothing Then
  69. ellipse.MyAnimatedEllipseGeometry.Center = ellipse.EllipseCenter
  70. End If
  71. If Not _mydelegate Is Nothing Then
  72. _mydelegate(obj, e)
  73. End If
  74. End Sub
  75. End Class