MyMsgText.xaml.vb 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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, "普通弹窗初始化失败", NotifyLevel.AllUsers)
  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, "普通弹窗加载失败", NotifyLevel.AllUsers)
  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(
  53. Sub()
  54. If Not WaitingMyMsgBox.Any() Then
  55. AniStart(AaColor(FrmMain.PanMsg, Grid.BackgroundProperty, New MyColor(0, 0, 0, 0) - FrmMain.PanMsg.Background, 200, Ease:=New AniEaseOutFluent(AniEasePower.Weak)))
  56. End If
  57. End Sub, 30),
  58. AaOpacity(Me, -Opacity, 80, 20),
  59. AaDouble(Sub(i) TransformPos.Y += i, 20 - TransformPos.Y, 150, 0, New AniEaseOutFluent),
  60. AaDouble(Sub(i) TransformRotate.Angle += i, 6 - TransformRotate.Angle, 150, 0, New AniEaseInFluent(AniEasePower.Weak)),
  61. AaCode(Sub() CType(Parent, Grid).Children.Remove(Me), , True)
  62. }, "MyMsgBox " & Uuid)
  63. End Sub
  64. Public Sub Btn1_Click() Handles Btn1.Click
  65. If MyConverter.IsExited Then Return
  66. If MyConverter.Button1Action IsNot Nothing Then
  67. MyConverter.Button1Action()
  68. Else
  69. MyConverter.IsExited = True
  70. MyConverter.Result = 1
  71. Close()
  72. End If
  73. End Sub
  74. Public Sub Btn2_Click() Handles Btn2.Click
  75. If MyConverter.IsExited Then Return
  76. If MyConverter.Button2Action IsNot Nothing Then
  77. MyConverter.Button2Action()
  78. Else
  79. MyConverter.IsExited = True
  80. MyConverter.Result = 2
  81. Close()
  82. End If
  83. End Sub
  84. Public Sub Btn3_Click() Handles Btn3.Click
  85. If MyConverter.IsExited Then Return
  86. If MyConverter.Button3Action IsNot Nothing Then
  87. MyConverter.Button3Action()
  88. Else
  89. MyConverter.IsExited = True
  90. MyConverter.Result = 3
  91. Close()
  92. End If
  93. End Sub
  94. Private Sub Drag(sender As Object, e As MouseButtonEventArgs) Handles PanBorder.MouseLeftButtonDown, LabTitle.MouseLeftButtonDown
  95. On Error Resume Next
  96. If e.GetPosition(ShapeLine).Y <= 2 Then FrmMain.DragMove()
  97. End Sub
  98. End Class