MyImage.vb 1.9 KB

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