MyMenuItem.vb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. Public Class MyMenuItem
  2. Inherits MenuItem
  3. Private Sub MyMenuItem_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
  4. If Icon IsNot Nothing Then
  5. Dim IconControl As Shapes.Path = GetTemplateChild("Icon")
  6. If IconControl IsNot Nothing Then IconControl.Data = (New GeometryConverter).ConvertFromString(Icon)
  7. End If
  8. End Sub
  9. '基础
  10. Public Uuid As Integer = GetUuid()
  11. '指向动画
  12. Private Const AnimationTimeIn As Integer = 100
  13. Private Const AnimationTimeOut As Integer = 200
  14. Private ColorName As String
  15. Private Sub RefreshColor() Handles Me.MouseEnter, Me.MouseLeave, Me.IsEnabledChanged
  16. '判断当前颜色
  17. Dim BackName As String, ForeName As String
  18. Dim Time As Integer
  19. If Not IsEnabled Then
  20. BackName = "ColorBrushTransparent"
  21. ForeName = "ColorBrushGray5"
  22. Time = AnimationTimeOut
  23. ElseIf IsMouseOver Then
  24. BackName = "ColorBrush6"
  25. ForeName = "ColorBrush2"
  26. Time = AnimationTimeIn
  27. Else
  28. BackName = "ColorBrushTransparent"
  29. ForeName = "ColorBrush1"
  30. Time = AnimationTimeOut
  31. End If
  32. '重复性验证
  33. If ColorName = BackName Then Exit Sub
  34. ColorName = BackName
  35. '触发颜色动画
  36. If IsLoaded AndAlso AniControlEnabled = 0 Then '防止默认属性变更触发动画
  37. '有动画
  38. AniStart({
  39. AaColor(Me, BackgroundProperty, BackName, Time),
  40. AaColor(Me, ForegroundProperty, ForeName, Time)
  41. }, "MyMenuItem Color " & Uuid)
  42. Else
  43. '无动画
  44. AniStop("MyMenuItem Color " & Uuid)
  45. SetResourceReference(BackgroundProperty, BackName)
  46. SetResourceReference(ForegroundProperty, ForeName)
  47. End If
  48. End Sub
  49. End Class