MyMsgSelect.xaml.vb 4.3 KB

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