MyMsgInput.xaml.vb 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. Public Class MyMsgInput
  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. MyConverter = Converter
  10. LabTitle.Text = Converter.Title
  11. LabText.Text = Converter.Text
  12. PanText.Visibility = If(Converter.Text = "", Visibility.Collapsed, Visibility.Visible)
  13. TextArea.Text = Converter.Content
  14. TextArea.HintText = Converter.HintText
  15. TextArea.ValidateRules = Converter.ValidateRules
  16. Btn1.Text = Converter.Button1
  17. If Converter.IsWarn Then
  18. Btn1.ColorType = MyButton.ColorState.Red
  19. LabTitle.SetResourceReference(TextBlock.ForegroundProperty, "ColorBrushRedLight")
  20. End If
  21. Btn2.Text = Converter.Button2
  22. Btn2.Visibility = If(Converter.Button2 = "", Visibility.Collapsed, Visibility.Visible)
  23. ShapeLine.StrokeThickness = GetWPFSize(1)
  24. Catch ex As Exception
  25. Logger.Error(ex, "输入弹窗初始化失败", LogBehavior.Toast)
  26. End Try
  27. End Sub
  28. Private Sub Load(sender As Object, e As EventArgs) Handles MyBase.Loaded
  29. Try
  30. 'UI 初始化
  31. If Btn2.IsVisible AndAlso Not Btn1.ColorType = MyButton.ColorState.Red Then Btn1.ColorType = MyButton.ColorState.Highlight
  32. TextArea.Focus()
  33. TextArea.SelectionStart = TextArea.Text.Length
  34. '动画
  35. Opacity = 0
  36. 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")
  37. AniStart({
  38. AaOpacity(Me, 1, 120, 60),
  39. AaDouble(Sub(i) TransformPos.Y += i, -TransformPos.Y, 300, 60, New AniEaseOutBack(AniEasePower.Weak)),
  40. AaDouble(Sub(i) TransformRotate.Angle += i, -TransformRotate.Angle, 300, 60, New AniEaseOutFluent(AniEasePower.Weak))
  41. }, "MyMsgBox " & Uuid)
  42. '记录日志
  43. Logger.Info($"输入弹窗:{LabTitle.Text}")
  44. Catch ex As Exception
  45. Logger.Error(ex, "输入弹窗加载失败", LogBehavior.Toast)
  46. End Try
  47. End Sub
  48. Private Sub Close()
  49. '结束线程阻塞
  50. MyConverter.WaitFrame.Continue = False
  51. Interop.ComponentDispatcher.PopModal()
  52. '动画
  53. AniStart({
  54. AaCode(
  55. Sub()
  56. If Not WaitingMyMsgBox.Any() Then
  57. AniStart(AaColor(FrmMain.PanMsg, Grid.BackgroundProperty, New MyColor(0, 0, 0, 0) - FrmMain.PanMsg.Background, 200, Ease:=New AniEaseOutFluent(AniEasePower.Weak)))
  58. End If
  59. End Sub, 30),
  60. AaOpacity(Me, -Opacity, 80, 20),
  61. AaDouble(Sub(i) TransformPos.Y += i, 20 - TransformPos.Y, 150, 0, New AniEaseOutFluent),
  62. AaDouble(Sub(i) TransformRotate.Angle += i, 6 - TransformRotate.Angle, 150, 0, New AniEaseInFluent(AniEasePower.Weak)),
  63. AaCode(Sub() CType(Parent, Grid).Children.Remove(Me), , True)
  64. }, "MyMsgBox " & Uuid)
  65. End Sub
  66. Public Sub Btn1_Click() Handles Btn1.Click
  67. TextArea.Validate() '#5773
  68. If MyConverter.IsExited OrElse Not TextArea.IsValidated Then Return
  69. MyConverter.IsExited = True
  70. MyConverter.Result = TextArea.Text
  71. Close()
  72. End Sub
  73. Public Sub Btn2_Click() Handles Btn2.Click
  74. If MyConverter.IsExited Then Return
  75. MyConverter.IsExited = True
  76. MyConverter.Result = Nothing
  77. Close()
  78. End Sub
  79. Private Sub TextCaption_ValidateChanged(sender As Object, e As EventArgs) Handles TextArea.ValidateChanged
  80. Btn1.IsEnabled = TextArea.IsValidated
  81. End Sub
  82. Private Sub Drag(sender As Object, e As MouseButtonEventArgs) Handles PanBorder.MouseLeftButtonDown, LabTitle.MouseLeftButtonDown
  83. On Error Resume Next
  84. If e.GetPosition(ShapeLine).Y <= 2 Then FrmMain.DragMove()
  85. End Sub
  86. End Class