MyMsgSelect.xaml.vb 6.1 KB

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