MyMenuItem.vb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. '对父级设置透明度
  9. If TypeOf Parent Is ContextMenu Then
  10. CType(Parent, ContextMenu).Opacity = Settings.Get(Of Integer)("UiLauncherTransparent") / 1000 + 0.4
  11. End If
  12. End Sub
  13. '基础
  14. Public Uuid As Integer = GetUuid()
  15. '指向动画
  16. Private Const AnimationTimeIn As Integer = 100
  17. Private Const AnimationTimeOut As Integer = 200
  18. Private ColorName As String
  19. Private Sub RefreshColor() Handles Me.MouseEnter, Me.MouseLeave, Me.IsEnabledChanged
  20. '判断当前颜色
  21. Dim BackName As String, ForeName As String
  22. Dim Time As Integer
  23. If Not IsEnabled Then
  24. BackName = "ColorBrushTransparent"
  25. ForeName = "ColorBrushGray5"
  26. Time = AnimationTimeOut
  27. ElseIf IsMouseOver Then
  28. BackName = "ColorBrush6"
  29. ForeName = "ColorBrush2"
  30. Time = AnimationTimeIn
  31. Else
  32. BackName = "ColorBrushTransparent"
  33. ForeName = "ColorBrush1"
  34. Time = AnimationTimeOut
  35. End If
  36. '重复性验证
  37. If ColorName = BackName Then Return
  38. ColorName = BackName
  39. '触发颜色动画
  40. If IsLoaded AndAlso AniControlEnabled = 0 Then '防止默认属性变更触发动画
  41. '有动画
  42. AniStart({
  43. AaColor(Me, BackgroundProperty, BackName, Time),
  44. AaColor(Me, ForegroundProperty, ForeName, Time)
  45. }, "MyMenuItem Color " & Uuid)
  46. Else
  47. '无动画
  48. AniStop("MyMenuItem Color " & Uuid)
  49. SetResourceReference(BackgroundProperty, BackName)
  50. SetResourceReference(ForegroundProperty, ForeName)
  51. End If
  52. End Sub
  53. Private Sub MyMenuItem_Click(sender As Object, e As RoutedEventArgs) Handles Me.Click
  54. RaiseCustomEvent()
  55. End Sub
  56. End Class