Dupe:WPF animated splash screen
我想为我的WPF应用程序显示一个闪屏。我想要做的是在我从文件中加载字典时显示它(加载大约需要5-6秒)。有没有办法在WPF中做到这一点?我会感谢一些教程,因为这比我发布的其他问题要复杂一点。
发布于 2010-10-12 19:44:00
请参阅WPF 3.5 SP1: Splash Screen
或者在VS2010中单击Solution Explorer
do Add -> New Item
,从已安装的模板列表中选择WPF
,Splash Screen
应位于列表底部的中间位置。
注意:在构造函数之后和主窗口Window_Loaded
回调之前/时,启动画面会被移除。我将我所有的初始化都移到了主窗口构造函数中,它工作得很好,而且非常简单。
发布于 2010-10-12 21:45:38
SplashScreen实际上只是另一个没有边框的窗口,它不能调整大小(也不能以任何方式与之交互)。你可能想从任务栏中隐藏它,在屏幕上居中,等等。尝试各种设置,直到你得到你想要的效果。
这里有一个我在大约5分钟内迅速准备好来证明这个理论的快速例子:
<Window x:Class="MyWhateverApp.MySplashScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ShowInTaskbar="False"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
Background="Transparent"
AllowsTransparency="True"
Title="Sandbox Splash Screen"
SizeToContent="Width"
Topmost="True"
Height="{Binding RelativeSource={RelativeSource Self},
Path=ActualWidth}">
<Border CornerRadius="8" Margin="15">
<Border.Background>
<ImageBrush ImageSource="Resources\sandtexture.jpeg"
Stretch="Fill" />
</Border.Background>
<Border.Effect>
<DropShadowEffect Color="#894F3B"
BlurRadius="10"
Opacity="0.75"
ShadowDepth="15" />
</Border.Effect>
<TextBlock FontSize="40"
FontFamily="Bauhaus 93"
Foreground="White"
Margin="10"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Text="WPF 3.5 Sandbox">
<TextBlock.Effect>
<DropShadowEffect Color="Black" />
</TextBlock.Effect>
</TextBlock>
</Border>
</Window>
接下来,修改App.xaml文件以删除启动窗口,并引发启动事件:
<Application x:Class="MyWhateverApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup">
<Application.Resources>
</Application.Resources>
</Application>
在代码隐藏中,以您认为最好的方式处理Application_Startup事件。例如:
Window1 mainWindow = null;
private void Application_Startup(object sender, StartupEventArgs e)
{
MySplashScreen splash = new MySplashScreen();
splash.Show();
mainWindow = new Window1();
mainWindow.Show();
splash.Close();
}
发布于 2010-10-12 19:46:24
简短的回答: Add -> New Item -> Splash Screen。它会在项目中转储一个PNG --只需修改这个。请注意,它支持完整的alpha透明度,因此可以包含阴影等。
https://stackoverflow.com/questions/3914213
复制相似问题