我有一个想要淡入的初始屏幕,而我的应用程序关闭并执行某些操作,然后一旦完成,如果经过一定时间,则关闭初始屏幕并加载主屏幕。
我遇到的问题是,当我循环检查时间是否已经过去时,它似乎没有处理我的故事板以淡入启动画面。
在阅读之后,我想我应该在不同的线程上启动启动画面?
继承人的代码:
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
MySplashScreen splash = new MySplashScreen();
splash.Show();
Stopwatch sw = new Stopwatch();
sw.Start();
while (sw.Elapsed.TotalSeconds < 10)
{
}
splash.Close();
MainWindow mw = new MainWindow();
mw.Show();
}
}
问题是当我添加动画时。就像它没有将任何处理器应用于淡入淡出一样,因为它卡在了 while 循环中。
<Window x:Class="Splash_Demo.MySplashScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="550" Width="900" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowStyle="None" ShowInTaskbar="False" Background="Transparent" AllowsTransparency="True" Opacity="0">
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="00:00:03" Storyboard.TargetProperty="Opacity" To="1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Canvas Height="498" Width="839">
<Canvas.Background>
<ImageBrush ImageSource="C:\Users\Ash\Downloads\XactSplash.png"/>
</Canvas.Background>
<Label Canvas.Left="291" FontFamily="Algerian" Canvas.Top="413" Name="Customer" Height="43" Width="185" HorizontalContentAlignment="Left" VerticalContentAlignment="Center"/>
<Image Canvas.Left="500" Canvas.Top="165" Height="164" Name="image1" Stretch="Fill" Width="211" Source="C:\Users\Ash\Downloads\Zerix.bmp" />
<Label Canvas.Left="191" Canvas.Top="376" FontSize="8" Content="Label" Height="19" Name="lblYear" Width="30" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" />
</Canvas>
</Window>