• WPF 启动页面 (原发布 csdn 2017-06-26 19:26:01)


    如果我写的有误,请及时与我联系,我立即改之以免继续误导他/她人。

    如果您有好的想法或者建议,请随时与我联系。

    wpf软件启动时,加载启动页面。软件初始化完成之后关闭页面。

    App.xaml.cs代码 (实现加载页面功能)

    public partial class App : Application
        {
            protected override void OnStartup(StartupEventArgs e)
            {
                var thread = new Thread(new ThreadStart(() =>
                {
                    WpfApplication1.MainWindow.window = new Window1();
                    WpfApplication1.MainWindow.window.Show();
                    WpfApplication1.MainWindow.window.Activate();
                    System.Windows.Threading.Dispatcher.Run();
                }));
                thread.SetApartmentState(ApartmentState.STA);
                thread.IsBackground = true;
                thread.Start();
                base.OnStartup(e);
            }
        }
    

    MainWindow.cs

    public partial class MainWindow : Window
        {
            public static Window1 window = null;
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                Thread.Sleep(1000*10);
    
                if (window != null)
                {
                    window.Dispatcher.BeginInvoke((Action) (() =>
                    {
                        window.Close();
                    }));
                }
            }
        }
    

    启动页面

    <Window x:Class="WpfApplication1.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApplication1"
            mc:Ignorable="d" WindowStartupLocation="CenterScreen" 
            Title="Window1" Height="300" Width="300" WindowStyle="None" MouseLeftButtonDown="Window_MouseLeftButtonDown">
        <Grid>
            <Image Name="splashScreenImage" Stretch="Fill" Grid.Row="0" Source="pp.jpg" />
            <Canvas Height="120" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5" VerticalAlignment="Center" Width="120">
                <Canvas.RenderTransform>
                    <RotateTransform x:Name="SpinnerRotate" Angle="0" />
                </Canvas.RenderTransform>
                <Canvas.Triggers>
                    <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                        <BeginStoryboard>
                            <BeginStoryboard.Storyboard>
                                <Storyboard>
                                    <DoubleAnimation Duration="0:0:2" From="0" RepeatBehavior="Forever" Storyboard.TargetName="SpinnerRotate" Storyboard.TargetProperty="(RotateTransform.Angle)" To="360" />
                                </Storyboard>
                            </BeginStoryboard.Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Canvas.Triggers>
                <Ellipse Canvas.Left="47.2783" Canvas.Top="0.5" Fill="Orange" Height="21.862" Opacity="1" Stretch="Fill" Width="21.835" />
                <Ellipse Canvas.Left="20.1696" Canvas.Top="9.76358" Fill="Orange" Height="21.862" Opacity="0.9" Stretch="Fill" Width="21.835" />
                <Ellipse Canvas.Left="2.86816" Canvas.Top="29.9581" Fill="Orange" Height="21.862" Opacity="0.8" Stretch="Fill" Width="21.835" />
                <Ellipse Canvas.Left="5.03758e-006" Canvas.Top="57.9341" Fill="Orange" Height="21.862" Opacity="0.7" Stretch="Fill" Width="21.835" />
                <Ellipse Canvas.Left="12.1203" Canvas.Top="83.3163" Fill="Orange" Height="21.862" Opacity="0.6" Stretch="Fill" Width="21.835" />
                <Ellipse Canvas.Left="36.5459" Canvas.Top="98.138" Fill="Orange" Height="21.862" Opacity="0.5" Stretch="Fill" Width="21.835" />
                <Ellipse Canvas.Left="64.6723" Canvas.Top="96.8411" Fill="Orange" Height="21.862" Opacity="0.4" Stretch="Fill" Width="21.835" />
                <Ellipse Canvas.Left="87.6176" Canvas.Top="81.2783" Fill="Orange" Height="21.862" Opacity="0.3" Stretch="Fill" Width="21.835" />
                <Ellipse Canvas.Left="98.165" Canvas.Top="54.414" Fill="Orange" Height="21.862" Opacity="0.2" Stretch="Fill" Width="21.835" />
                <Ellipse Canvas.Left="92.9838" Canvas.Top="26.9938" Fill="Orange" Height="21.862" Opacity="0.1" Stretch="Fill" Width="21.835" />
            </Canvas>
        </Grid>
    </Window>
    
    private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        base.DragMove();
    }
    

    完整代码

    点击打开链接

  • 相关阅读:
    c# winform DataGridView单击选中一整行,只能单选,不能选择多行,只能选择一行
    c# winform 子窗体向父窗体传值
    as中使用字体
    出现“正尝试安装的adobe flash player不是最新版本”的解决方法
    打印等腰三角形
    【Array数组】数组的浅复制和深复制
    AIR程序app.xml配置详解(转)
    【Array数组】使用slice返回数组中的元素
    creationComplete和applicationComplete区别
    【XML】遍历xml子节点
  • 原文地址:https://www.cnblogs.com/njit-77/p/11469082.html
Copyright © 2020-2023  润新知