gpt4 book ai didi

wpf - 如何正确协调 Windows 加载动画和 C# 事件?

转载 作者:行者123 更新时间:2023-12-04 22:09:42 25 4
gpt4 key购买 nike

我的 WPF 应用程序有一个窗口加载动画,它是我使用 Blend 创建的。实际的动画工作正常,但如果我向我的窗口加载事件添加逻辑(使用 C#),动画将在窗口最终呈现时跳到结束。

我最初的计划是使用 Threading 来解决这个问题,但这也行不通:

private void MyWindow_Loaded(object sender, RoutedEventArgs e)
{

dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 30);
dispatcherTimer.Start();

lstRecipients.Visibility = Visibility.Hidden;
windowAdorner = new TransparentAdorner(BorderGrid);

if (!StaticHelpers.AWSConfigurationExists())
{
this.IsEnabled = false;
GettingStarted gettingStarted = new GettingStarted(this);
gettingStarted.Owner = this;
gettingStarted.ShowDialog();
this.IsEnabled = true;
}
else
{
Task SetAWSLabelsTask = new Task(new Action(() => SetAWSLabels()));
SetAWSLabelsTask.Start();

}

Task bounceHandler = new Task(new Action(() => processBounce()));
bounceHandler.Start();
//processBounce();

Task unSubscribeHandler = new Task(new Action(() => handleUnsubscriptions()));
unSubscribeHandler.Start();
}

我假设系统正忙于创建线程,并且创建由 UI 线程处理,以至于在呈现窗口时动画已经完成。

我缺少的是一种协调动画的好方法,这样我在 MyWindow_Loaded 中的任何业务逻辑都只会在动画加载完成后发生。

这可能吗?

编辑:我也试过线程休眠,但这也没有用。

最佳答案

好的,问题解决了。

在 XAML 中向 Storyboard添加了一个新的事件处理程序:

<Storyboard x:Key="SESLogoLoad" Completed="StoryCompleted">

然后使用 C# 手动创建了一个方法:

private void StoryCompleted(object sender, EventArgs e)
{
//Windows onload stuff goes here...
}

关于wpf - 如何正确协调 Windows 加载动画和 C# 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18263336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com