MyMsgInput.xaml.vb 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. Btn3.Name = Btn3.Name & GetUuid()
  10. MyConverter = Converter
  11. LabTitle.Text = Converter.Title
  12. TextCaption.Text = Converter.Content
  13. TextCaption.HintText = Converter.HintText
  14. TextCaption.ValidateRules = Converter.ValidateRules
  15. Btn1.Text = Converter.Button1
  16. If Converter.IsWarn Then
  17. Btn1.ColorType = MyButton.ColorState.Red
  18. LabTitle.SetResourceReference(TextBlock.ForegroundProperty, "ColorBrushRedLight")
  19. ShapeLine.SetResourceReference(Rectangle.FillProperty, "ColorBrushRedLight")
  20. End If
  21. Btn2.Text = Converter.Button2
  22. Btn3.Text = Converter.Button3
  23. Btn2.Visibility = If(Converter.Button2 = "", Visibility.Collapsed, Visibility.Visible)
  24. Btn3.Visibility = If(Converter.Button3 = "", Visibility.Collapsed, Visibility.Visible)
  25. 'If Converter.Caption > 0 Then
  26. ' TextCaption.Focus()
  27. ' TextCaption.Select(Converter.Caption.Length - 1, 0)
  28. 'End If
  29. Catch ex As Exception
  30. Log(ex, "输入弹窗初始化失败", LogLevel.Hint)
  31. End Try
  32. End Sub
  33. Private Sub Load(sender As Object, e As EventArgs) Handles MyBase.Loaded
  34. Try
  35. 'UI 初始化
  36. If Btn2.IsVisible AndAlso Not Btn1.ColorType = MyButton.ColorState.Red Then Btn1.ColorType = MyButton.ColorState.Highlight
  37. ShapeLine.StrokeThickness = GetWPFSize(1)
  38. Measure(New Size(FrmMain.Width, FrmMain.Height))
  39. Arrange(New Rect(0, 0, FrmMain.Width, FrmMain.Height))
  40. If FrmMain.Width - ActualWidth < 20 Then Width = FrmMain.Width - GetWPFSize(2)
  41. TextCaption.Focus()
  42. '动画
  43. AniStart({
  44. AaColor(FrmMain.PanMsg, Grid.BackgroundProperty, New MyColor(60, 0, 0, 0), 250, , New AniEaseInFluent),
  45. AaColor(PanBorder, Border.BackgroundProperty, New MyColor(255, 0, 0, 0), 150, , New AniEaseInFluent),
  46. AaOpacity(EffectShadow, 0.75, 400, 50),
  47. AaWidth(ShapeLine, ShapeLine.ActualWidth, 250, 100, New AniEaseOutFluent),
  48. AaOpacity(ShapeLine, 1, 200, 100),
  49. AaWidth(LabTitle, LabTitle.ActualWidth, 200, 100, New AniEaseOutFluent),
  50. AaOpacity(LabTitle, 1, 150, 150),
  51. AaOpacity(PanCaption, 1, 150, 150),
  52. AaOpacity(Btn1, 1, 150, 100),
  53. AaOpacity(Btn2, 1, 150, 150),
  54. AaOpacity(Btn3, 1, 150, 200),
  55. AaCode(Sub()
  56. ShapeLine.MinWidth = ShapeLine.ActualWidth
  57. ShapeLine.HorizontalAlignment = HorizontalAlignment.Stretch
  58. ShapeLine.Width = Double.NaN
  59. LabTitle.Width = Double.NaN
  60. LabTitle.TextTrimming = TextTrimming.CharacterEllipsis
  61. End Sub, 350)
  62. }, "MyMsgBox Start " & Uuid)
  63. '动画初始化
  64. ShapeLine.Width = 0
  65. ShapeLine.HorizontalAlignment = HorizontalAlignment.Center
  66. LabTitle.Width = 0
  67. LabTitle.Opacity = 0
  68. LabTitle.TextWrapping = TextWrapping.NoWrap
  69. PanCaption.Opacity = 0
  70. '记录日志
  71. Log("[Control] 输入弹窗:" & LabTitle.Text)
  72. Catch ex As Exception
  73. Log(ex, "输入弹窗加载失败", LogLevel.Hint)
  74. End Try
  75. End Sub
  76. Private Sub Close()
  77. '结束线程阻塞
  78. MyConverter.WaitFrame.Continue = False
  79. Interop.ComponentDispatcher.PopModal()
  80. '弹窗动画
  81. LabTitle.TextTrimming = TextTrimming.None
  82. LabTitle.TextWrapping = TextWrapping.NoWrap
  83. AniStart({
  84. AaColor(FrmMain.PanMsg, Grid.BackgroundProperty, New MyColor(-60, 0, 0, 0), 350, , New AniEaseInFluent),
  85. AaColor(PanBorder, Border.BackgroundProperty, New MyColor(-255, 0, 0, 0), 300, 100, New AniEaseInFluent),
  86. AaOpacity(EffectShadow, -0.75, 150),
  87. AaWidth(ShapeLine, -ShapeLine.ActualWidth, 250, , New AniEaseInFluent),
  88. AaOpacity(ShapeLine, -1, 150, 100),
  89. AaWidth(LabTitle, -LabTitle.ActualWidth, 250),
  90. AaOpacity(LabTitle, -1, 200),
  91. AaOpacity(PanCaption, -1, 200),
  92. AaOpacity(Btn1, -1, 150),
  93. AaOpacity(Btn2, -1, 150, 50),
  94. AaOpacity(Btn3, -1, 150, 100),
  95. AaCode(Sub() CType(Parent, Grid).Children.Remove(Me), , True)
  96. }, "MyMsgBox Close " & Uuid)
  97. End Sub
  98. Public Sub Btn1_Click() Handles Btn1.Click
  99. If MyConverter.IsExited OrElse Not TextCaption.ValidateResult = "" Then Exit Sub
  100. MyConverter.IsExited = True
  101. MyConverter.Result = TextCaption.Text
  102. Close()
  103. End Sub
  104. Private Sub Btn2_Click() Handles Btn2.Click
  105. If MyConverter.IsExited Then Exit Sub
  106. MyConverter.IsExited = True
  107. MyConverter.Result = Nothing
  108. Close()
  109. End Sub
  110. Private Sub Btn3_Click() Handles Btn3.Click
  111. If MyConverter.IsExited Then Exit Sub
  112. MyConverter.IsExited = True
  113. MyConverter.Result = Nothing
  114. Close()
  115. End Sub
  116. Private Sub TextCaption_ValidateChanged(sender As Object, e As EventArgs) Handles TextCaption.ValidateChanged
  117. Btn1.IsEnabled = TextCaption.ValidateResult = ""
  118. End Sub
  119. Private Sub Drag(sender As Object, e As MouseButtonEventArgs) Handles PanBorder.MouseLeftButtonDown, LabTitle.MouseLeftButtonDown
  120. On Error Resume Next
  121. If e.GetPosition(ShapeLine).Y <= 2 Then FrmMain.DragMove()
  122. End Sub
  123. End Class