11using System . Windows ;
22using System . Windows . Media . Animation ;
33
4- namespace ComputerLock
4+ namespace ComputerLock ;
5+ /// <summary>
6+ /// WindowPopup.xaml 的交互逻辑
7+ /// </summary>
8+ public partial class WindowPopup : Window
59{
6- /// <summary>
7- /// WindowPopup.xaml 的交互逻辑
8- /// </summary>
9- public partial class WindowPopup : Window
10+ public WindowPopup ( string message )
1011 {
11- public WindowPopup ( string message )
12- {
13- InitializeComponent ( ) ;
14- TxtMessage . Text = message ;
15- Loaded += WindowPopup_Loaded ;
16- }
17- private void WindowPopup_Loaded ( object sender , RoutedEventArgs e )
12+ InitializeComponent ( ) ;
13+ TxtMessage . Text = message ;
14+ Loaded += WindowPopup_Loaded ;
15+ }
16+ private void WindowPopup_Loaded ( object sender , RoutedEventArgs e )
17+ {
18+ // 在窗口加载完成后开始渐入动画
19+ var fadeInAnimation = new DoubleAnimation
1820 {
19- // 在窗口加载完成后开始渐入动画
20- var fadeInAnimation = new DoubleAnimation
21- {
22- From = 0 ,
23- To = 1 ,
24- Duration = TimeSpan . FromMilliseconds ( 300 ) ,
25- } ;
21+ From = 0 ,
22+ To = 1 ,
23+ Duration = TimeSpan . FromMilliseconds ( 300 ) ,
24+ } ;
2625
27- BeginAnimation ( UIElement . OpacityProperty , fadeInAnimation ) ;
28- }
26+ BeginAnimation ( UIElement . OpacityProperty , fadeInAnimation ) ;
27+
28+ UpdateWindowPosition ( ) ;
29+ }
2930
30- public void CloseWindow ( )
31+ private void UpdateWindowPosition ( )
32+ {
33+ double primaryScreenWidth = SystemParameters . PrimaryScreenWidth ;
34+ double primaryScreenHeight = SystemParameters . PrimaryScreenHeight ;
35+ Left = ( primaryScreenWidth - ActualWidth ) / 2 ;
36+ Top = ( primaryScreenHeight - ActualHeight ) / 2 ;
37+ }
38+
39+ public void CloseWindow ( )
40+ {
41+ // 在窗口关闭时开始渐出动画
42+ var fadeOutAnimation = new DoubleAnimation
3143 {
32- // 在窗口关闭时开始渐出动画
33- var fadeOutAnimation = new DoubleAnimation
34- {
35- From = 1 ,
36- To = 0 ,
37- Duration = TimeSpan . FromMilliseconds ( 300 ) ,
38- } ;
44+ From = 1 ,
45+ To = 0 ,
46+ Duration = TimeSpan . FromMilliseconds ( 300 ) ,
47+ } ;
3948
40- fadeOutAnimation . Completed += ( _ , _ ) => Close ( ) ;
49+ fadeOutAnimation . Completed += ( _ , _ ) => Close ( ) ;
4150
42- BeginAnimation ( UIElement . OpacityProperty , fadeOutAnimation ) ;
43- }
51+ BeginAnimation ( UIElement . OpacityProperty , fadeOutAnimation ) ;
4452 }
45- }
53+ }
0 commit comments