WPF实现等待界面

时间:2025-01-25 09:05:57
// An highlighted block /// <summary> /// 在本窗体显示Loading /// </summary> /// <param name="wins"></param> public static async void ShowLoad(System.Windows.Window wins) { await Task.Run(delegate () { wins.Dispatcher.Invoke(delegate () { window = new Window(); System.Windows.Controls.Button button = new System.Windows.Controls.Button(); // = "加载中"; button.Width = 50; button.Height = 50; button.RenderTransform = new RotateTransform(); button.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5); Storyboard story = new Storyboard(); DoubleAnimation da = new DoubleAnimation(0, 360, new Duration(TimeSpan.FromSeconds(3))); Storyboard.SetTarget(da, button); Storyboard.SetTargetProperty(da, new PropertyPath("")); da.RepeatBehavior = RepeatBehavior.Forever; story.Children.Add(da); story.Begin(); window.Content = button; window.Name = "loading"; window.Topmost = true; window.WindowStyle = WindowStyle.None; window.AllowsTransparency = true; window.Opacity = 0.5; window.Width = wins.Width; window.Height = wins.Height; window.Left = wins.Left; window.Top = wins.Top; window.ShowDialog(); }); }); }