MyMenuItem.vb 2.0 KB

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