欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-11-14 17:34:16
如果我写的有误,请及时与我联系,我立即改之以免继续误导他/她人。 如果您有好的想法或者建议,请随时与我联系。 wpf软件启动时,加载启动页面。软件初始化完成之后关闭页面。 App.xaml.cs代码 (实现加载页面功能) MainWindow.cs 启动页面 完整代码 "点击打开链接" ......

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

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

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();
}

完整代码