MyImage.vb 1.8 KB

12345678910111213141516171819202122232425262728293031323334
  1. Public Class MyImage
  2. Inherits Image
  3. '事件
  4. Public Uuid As Integer = GetUuid()
  5. Private _SourceData As String = ""
  6. ''' <summary>
  7. ''' 重写Image的Source属性
  8. ''' </summary>
  9. Public Shadows Property Source As String
  10. Get
  11. Return _SourceData
  12. End Get
  13. Set(value As String)
  14. SetImage(value)
  15. End Set
  16. End Property
  17. Public Shared Shadows ReadOnly SourceProperty As DependencyProperty = DependencyProperty.Register("Source", GetType(String), GetType(MyImage), New PropertyMetadata(New PropertyChangedCallback(
  18. Sub(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
  19. If Not IsNothing(sender) Then
  20. CType(sender, MyImage).SetImage(e.NewValue)
  21. End If
  22. End Sub)))
  23. Private Sub SetImage(source As String)
  24. If Me Is Nothing Then Exit Sub
  25. If String.IsNullOrEmpty(source) Then Exit Sub
  26. _SourceData = source
  27. MyBase.Source = New MyBitmap(_SourceData)
  28. End Sub
  29. End Class