sok*_*vic 14 wpf splash-screen
Dupe:WPF动画启动画面
我想为我的WPF应用程序显示一个启动画面.我想要做的是在从文件加载字典时显示它(加载大约需要5-6秒).有没有办法在WPF中实现这一目标?我会很感激一些教程,因为这比我发布的其他问题要复杂一些.
Won*_*ane 20
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>
Run Code Online (Sandbox Code Playgroud)
接下来,修改App.xaml文件以删除启动窗口,然后引发Startup事件:
<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>
Run Code Online (Sandbox Code Playgroud)
在代码隐藏中,以您认为最好的方式处理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();
}
Run Code Online (Sandbox Code Playgroud)
Ric*_*son 12
或者在VS2010中点击" Solution Explorer
执行" Add -> New Item
,WPF
从已安装模板列表中选择,并且Splash Screen
应该位于中间列表的底部.
注意:构造函数之后以及主窗口Window_Loaded
回调之前/之后将删除启动屏幕.我把所有的初始化都移到了主窗口构造函数中,它很有效,而且非常简单.
简答:添加 - >新项目 - >启动画面.它在项目中转储PNG - 只需修改它.请注意,它支持完整的alpha透明度,因此可以包含阴影等...
归档时间: |
|
查看次数: |
21023 次 |
最近记录: |