MyHint.xaml.vb 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. Imports System.Windows.Markup
  2. <ContentProperty("Inlines")>
  3. Public Class MyHint
  4. Public Uuid As Integer = GetUuid()
  5. '边框
  6. Public Property HasBorder As Boolean
  7. Get
  8. Return BorderThickness.Top > 0
  9. End Get
  10. Set(value As Boolean)
  11. If value Then
  12. BorderThickness = New Thickness(3, GetWPFSize(1), GetWPFSize(1), GetWPFSize(1))
  13. Else
  14. BorderThickness = New Thickness(3, 0, 0, 0)
  15. End If
  16. End Set
  17. End Property
  18. '配色
  19. Public Enum Themes
  20. Blue = 0
  21. Red = 1
  22. Yellow = 2
  23. End Enum
  24. Public Property Theme As Themes
  25. Get
  26. Return _ColorType
  27. End Get
  28. Set(value As Themes)
  29. _ColorType = value
  30. UpdateUI()
  31. End Set
  32. End Property
  33. Private _ColorType As Themes = Themes.Red
  34. Private Sub UpdateUI() Handles Me.Loaded
  35. Select Case Theme
  36. Case Themes.Blue
  37. Background = New MyColor("#d9ecff")
  38. BorderBrush = New MyColor("#1172D4")
  39. LabText.Foreground = New MyColor("#0F64B8")
  40. BtnClose.Foreground = New MyColor("#0F64B8")
  41. Case Themes.Red
  42. Background = New MyColor("#ffdddf")
  43. BorderBrush = New MyColor("#d82929")
  44. LabText.Foreground = New MyColor("#bf0b0b")
  45. BtnClose.Foreground = New MyColor("#bf0b0b")
  46. Case Themes.Yellow
  47. Background = New MyColor("#ffebd7")
  48. BorderBrush = New MyColor("#f57a00")
  49. LabText.Foreground = New MyColor("#d86c00")
  50. BtnClose.Foreground = New MyColor("#d86c00")
  51. End Select
  52. End Sub
  53. <Obsolete("IsWarn 已过时。请换用 Theme 属性。")>
  54. Public Property IsWarn As Boolean
  55. Get
  56. Return Theme = Themes.Red
  57. End Get
  58. Set(value As Boolean)
  59. Theme = If(value, Themes.Red, Themes.Blue)
  60. End Set
  61. End Property
  62. Public Shared ReadOnly IsWarnProperty As DependencyProperty =
  63. DependencyProperty.Register("IsWarn", GetType(Boolean), GetType(MyHint), New PropertyMetadata(True,
  64. Sub(d As MyHint, e As DependencyPropertyChangedEventArgs)
  65. d.Theme = If(e.NewValue, Themes.Red, Themes.Blue)
  66. End Sub))
  67. '文本
  68. Public ReadOnly Property Inlines As InlineCollection
  69. Get
  70. Return LabText.Inlines
  71. End Get
  72. End Property
  73. Public Property Text As String
  74. Get
  75. Return GetValue(TextProperty)
  76. End Get
  77. Set(value As String)
  78. SetValue(TextProperty, value)
  79. End Set
  80. End Property
  81. Public Shared ReadOnly TextProperty As DependencyProperty =
  82. DependencyProperty.Register("Text", GetType(String), GetType(MyHint), New PropertyMetadata("",
  83. Sub(d As MyHint, e As DependencyPropertyChangedEventArgs)
  84. d.LabText.Text = e.NewValue
  85. End Sub))
  86. '关闭按钮
  87. Public Property CanClose As Boolean
  88. Get
  89. Return BtnClose.Visibility = Visibility.Visible
  90. End Get
  91. Set(value As Boolean)
  92. BtnClose.Visibility = If(value, Visibility.Visible, Visibility.Collapsed)
  93. End Set
  94. End Property
  95. Public Property RelativeSetup As String = ""
  96. Private Sub MyHint_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
  97. If CanClose AndAlso Settings.Get(Of Boolean)(RelativeSetup) Then Visibility = Visibility.Collapsed
  98. End Sub
  99. Private Sub BtnClose_Click(sender As Object, e As EventArgs) Handles BtnClose.Click
  100. Settings.SetSafe(RelativeSetup, True)
  101. AniDispose(Me, False)
  102. End Sub
  103. '触发点击事件
  104. Public Event Click(sender As Object, e As MouseButtonEventArgs)
  105. Private IsMouseDown As Boolean = False
  106. Private Sub MyHint_MouseUp(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonUp
  107. If Not IsMouseDown Then Return
  108. IsMouseDown = False
  109. Logger.Info($"按下提示条{If(String.IsNullOrEmpty(Name), "", ":" & Name)}")
  110. RaiseEvent Click(sender, e)
  111. If e.Handled Then Return
  112. e.Handled = True
  113. RaiseCustomEvent() '自定义事件
  114. End Sub
  115. Private Sub MyHint_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
  116. IsMouseDown = True
  117. End Sub
  118. Private Sub MyHint_MouseLeave() Handles Me.MouseLeave
  119. IsMouseDown = False
  120. End Sub
  121. End Class
  122. Partial Public Module ModAnimation
  123. Public Sub AniDispose(Control As MyHint, RemoveFromChildren As Boolean, Optional CallBack As ParameterizedThreadStart = Nothing)
  124. If Not Control.IsHitTestVisible Then Return
  125. Control.IsHitTestVisible = False
  126. AniStart({
  127. AaScaleTransform(Control, -0.08, 200,, New AniEaseInFluent),
  128. AaOpacity(Control, -1, 200,, New AniEaseOutFluent),
  129. AaHeight(Control, -Control.ActualHeight, 150, 100, New AniEaseOutFluent),
  130. AaCode(
  131. Sub()
  132. If RemoveFromChildren Then
  133. CType(Control.Parent, Object).Children.Remove(Control)
  134. Else
  135. Control.Visibility = Visibility.Collapsed
  136. End If
  137. If CallBack IsNot Nothing Then CallBack(Control)
  138. End Sub,, True)
  139. }, "MyCard Dispose " & Control.Uuid)
  140. End Sub
  141. End Module