MyMsgText.xaml.vb 5.4 KB

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