MyMsgSelect.xaml.vb 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. Public Class MyMsgSelect
  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. Btn1.Text = Converter.Button1
  12. If Converter.IsWarn Then
  13. Btn1.ColorType = MyButton.ColorState.Red
  14. LabTitle.SetResourceReference(TextBlock.ForegroundProperty, "ColorBrushRedLight")
  15. End If
  16. Btn2.Text = Converter.Button2
  17. Btn2.Visibility = If(Converter.Button2 = "", Visibility.Collapsed, Visibility.Visible)
  18. ShapeLine.StrokeThickness = GetWPFSize(1)
  19. '添加选择控件
  20. Btn1.IsEnabled = False
  21. For Each Content In Converter.Content
  22. Content = MyVirtualizingElement.TryInit(Content)
  23. Dim Selection As IMyRadio = Content
  24. PanSelection.Children.Add(Selection)
  25. AddHandler Selection.Check, AddressOf OnChecked
  26. If TypeOf Selection Is MyListItem Then
  27. CType(Selection, MyListItem).Type = MyListItem.CheckType.RadioBox
  28. CType(Selection, MyListItem).MinHeight = 24
  29. Else
  30. CType(Selection, MyRadioBox).MinHeight = 24
  31. End If
  32. Next
  33. Catch ex As Exception
  34. Logger.Error(ex, "选择弹窗初始化失败", LogBehavior.Toast)
  35. End Try
  36. End Sub
  37. Private Sub Load(sender As Object, e As EventArgs) Handles MyBase.Loaded
  38. Try
  39. 'UI 初始化
  40. If Btn2.IsVisible AndAlso Not Btn1.ColorType = MyButton.ColorState.Red Then Btn1.ColorType = MyButton.ColorState.Highlight
  41. '动画
  42. Opacity = 0
  43. 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")
  44. AniStart({
  45. AaOpacity(Me, 1, 120, 60),
  46. AaDouble(Sub(i) TransformPos.Y += i, -TransformPos.Y, 300, 60, New AniEaseOutBack(AniEasePower.Weak)),
  47. AaDouble(Sub(i) TransformRotate.Angle += i, -TransformRotate.Angle, 300, 60, New AniEaseOutFluent(AniEasePower.Weak))
  48. }, "MyMsgBox " & Uuid)
  49. '记录日志
  50. Logger.Info($"选择弹窗:{LabTitle.Text}")
  51. Catch ex As Exception
  52. Logger.Error(ex, "选择弹窗加载失败", LogBehavior.Toast)
  53. End Try
  54. End Sub
  55. Private Sub Close()
  56. '结束线程阻塞
  57. MyConverter.WaitFrame.Continue = False
  58. Interop.ComponentDispatcher.PopModal()
  59. '动画
  60. AniStart({
  61. AaCode(
  62. Sub()
  63. If Not WaitingMyMsgBox.Any() Then
  64. AniStart(AaColor(FrmMain.PanMsg, Grid.BackgroundProperty, New MyColor(0, 0, 0, 0) - FrmMain.PanMsg.Background, 200, Ease:=New AniEaseOutFluent(AniEasePower.Weak)))
  65. End If
  66. End Sub, 30),
  67. AaOpacity(Me, -Opacity, 80, 20),
  68. AaDouble(Sub(i) TransformPos.Y += i, 20 - TransformPos.Y, 150, 0, New AniEaseOutFluent),
  69. AaDouble(Sub(i) TransformRotate.Angle += i, 6 - TransformRotate.Angle, 150, 0, New AniEaseInFluent(AniEasePower.Weak)),
  70. AaCode(Sub() CType(Parent, Grid).Children.Remove(Me), , True)
  71. }, "MyMsgBox " & Uuid)
  72. End Sub
  73. Public Sub Btn1_Click() Handles Btn1.Click
  74. If MyConverter.IsExited OrElse SelectedIndex = -1 Then Return
  75. MyConverter.IsExited = True
  76. MyConverter.Result = SelectedIndex
  77. Close()
  78. End Sub
  79. Public Sub Btn2_Click() Handles Btn2.Click
  80. If MyConverter.IsExited Then Return
  81. MyConverter.IsExited = True
  82. MyConverter.Result = Nothing
  83. Close()
  84. End Sub
  85. Private SelectedIndex As Integer = -1
  86. Private Sub OnChecked(sender As IMyRadio, e As EventArgs)
  87. Btn1.IsEnabled = True
  88. SelectedIndex = PanSelection.Children.IndexOf(sender)
  89. End Sub
  90. Private Sub Drag(sender As Object, e As MouseButtonEventArgs) Handles PanBorder.MouseLeftButtonDown, LabTitle.MouseLeftButtonDown
  91. On Error Resume Next
  92. If e.GetPosition(ShapeLine).Y <= 2 Then FrmMain.DragMove()
  93. End Sub
  94. End Class