MyMsgText.xaml.vb 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. Public Class MyMsgText
  2. Private ReadOnly MyConverter As MyMsgBoxConverter
  3. Private ReadOnly Uuid As Integer = GetUuid()
  4. Public Sub New(Converter As MyMsgBoxConverter)
  5. Try
  6. InitializeComponent()
  7. Btn1.Name = Btn1.Name & GetUuid()
  8. Btn2.Name = Btn2.Name & GetUuid()
  9. Btn3.Name = Btn3.Name & GetUuid()
  10. MyConverter = Converter
  11. LabTitle.Text = Converter.Title
  12. LabCaption.Text = Converter.Text
  13. Btn1.Text = Converter.Button1
  14. If Converter.IsWarn Then
  15. Btn1.ColorType = MyButton.ColorState.Red
  16. LabTitle.SetResourceReference(TextBlock.ForegroundProperty, "ColorBrushRedLight")
  17. End If
  18. Btn2.Text = Converter.Button2
  19. Btn3.Text = Converter.Button3
  20. Btn2.Visibility = If(Converter.Button2 = "", Visibility.Collapsed, Visibility.Visible)
  21. Btn3.Visibility = If(Converter.Button3 = "", Visibility.Collapsed, Visibility.Visible)
  22. ShapeLine.StrokeThickness = GetWPFSize(1)
  23. Catch ex As Exception
  24. Log(ex, "普通弹窗初始化失败", LogLevel.Hint)
  25. End Try
  26. End Sub
  27. Private Sub Load(sender As Object, e As EventArgs) Handles MyBase.Loaded
  28. Try
  29. 'UI 初始化
  30. If Btn2.IsVisible AndAlso Not Btn1.ColorType = MyButton.ColorState.Red Then Btn1.ColorType = MyButton.ColorState.Highlight
  31. Btn1.Focus()
  32. '动画
  33. Opacity = 0
  34. AniStart(AaColor(FrmMain.PanMsg, Grid.BackgroundProperty, If(MyConverter.IsWarn, New MyColor(140, 80, 0, 0), New MyColor(90, 0, 0, 0)) - FrmMain.PanMsg.Background, 200), "PanMsg Background")
  35. AniStart({
  36. AaOpacity(Me, 1, 120, 60),
  37. AaDouble(Sub(i) TransformPos.Y += i, -TransformPos.Y, 300, 60, New AniEaseOutBack(AniEasePower.Weak)),
  38. AaDouble(Sub(i) TransformRotate.Angle += i, -TransformRotate.Angle, 300, 60, New AniEaseOutFluent(AniEasePower.Weak))
  39. }, "MyMsgBox " & Uuid)
  40. '记录日志
  41. Log("[Control] 普通弹窗:" & LabTitle.Text & vbCrLf & LabCaption.Text)
  42. Catch ex As Exception
  43. Log(ex, "普通弹窗加载失败", LogLevel.Hint)
  44. End Try
  45. End Sub
  46. Private Sub Close()
  47. '结束线程阻塞
  48. If MyConverter.ForceWait OrElse Not MyConverter.Button2 = "" Then MyConverter.WaitFrame.Continue = False
  49. Interop.ComponentDispatcher.PopModal()
  50. '动画
  51. AniStart({
  52. AaCode(Sub()
  53. If WaitingMyMsgBox.Count = 0 Then
  54. AniStart(AaColor(FrmMain.PanMsg, Grid.BackgroundProperty, New MyColor(0, 0, 0, 0) - FrmMain.PanMsg.Background, 200, Ease:=New AniEaseOutFluent(AniEasePower.Weak)))
  55. End If
  56. End Sub, 30),
  57. AaOpacity(Me, -Opacity, 80, 20),
  58. AaDouble(Sub(i) TransformPos.Y += i, 20 - TransformPos.Y, 150, 0, New AniEaseOutFluent),
  59. AaDouble(Sub(i) TransformRotate.Angle += i, 6 - TransformRotate.Angle, 150, 0, New AniEaseInFluent(AniEasePower.Weak)),
  60. AaCode(Sub() CType(Parent, Grid).Children.Remove(Me), , True)
  61. }, "MyMsgBox " & Uuid)
  62. End Sub
  63. Public Sub Btn1_Click() Handles Btn1.Click
  64. If MyConverter.IsExited Then Exit Sub
  65. If MyConverter.Button1Action IsNot Nothing Then
  66. MyConverter.Button1Action()
  67. Else
  68. MyConverter.IsExited = True
  69. MyConverter.Result = 1
  70. Close()
  71. End If
  72. End Sub
  73. Public Sub Btn2_Click() Handles Btn2.Click
  74. If MyConverter.IsExited Then Exit Sub
  75. If MyConverter.Button2Action IsNot Nothing Then
  76. MyConverter.Button2Action()
  77. Else
  78. MyConverter.IsExited = True
  79. MyConverter.Result = 2
  80. Close()
  81. End If
  82. End Sub
  83. Public Sub Btn3_Click() Handles Btn3.Click
  84. If MyConverter.IsExited Then Exit Sub
  85. If MyConverter.Button3Action IsNot Nothing Then
  86. MyConverter.Button3Action()
  87. Else
  88. MyConverter.IsExited = True
  89. MyConverter.Result = 3
  90. Close()
  91. End If
  92. End Sub
  93. Private Sub Drag(sender As Object, e As MouseButtonEventArgs) Handles PanBorder.MouseLeftButtonDown, LabTitle.MouseLeftButtonDown
  94. On Error Resume Next
  95. If e.GetPosition(ShapeLine).Y <= 2 Then FrmMain.DragMove()
  96. End Sub
  97. End Class