如何将启动画面与登录窗口和主窗口链接

时间:2015-04-21 06:42:13

标签: c# wpf

我有一个带有这三个分开的东西的WPF应用程序:

  • 启动画面
  • 登录窗口
  • 主窗口

当我打开应用程序时,首先会显示启动画面一段时间,然后进入登录窗口。用户登录成功后,启动画面将再次显示,最后进入主窗口。它是在处理线程吗?关于如何将这三件事联系在一起的任何建议?

3 个答案:

答案 0 :(得分:1)

您可以使用SplashScreen课程执行此操作。你必须在两个窗口的构造函数中显示/隐藏启动画面。

Public LoginWindow ()
{    
  //Show splash screen
  SplashScreen splashScreen = new SplashScreen("imageSource");
  splashScreen.Show(false, false);

  //Do any operation here

  //Closing the Splashscreen with fadding effect
  splashScreen.Close(TimeSpan.FromSeconds(1));

}

Public MainWindow ()
{
  //Show splash screen
  SplashScreen splashScreen = new SplashScreen("imageSource");
  splashScreen.Show(false, false);

  //Do any operation here

  //Closing the Splashscreen with fadding effect
  splashScreen.Close(TimeSpan.FromSeconds(1));
}

答案 1 :(得分:0)

嗯,我认为这可能会对你有所帮助: - > http://blog.dontpaniclabs.com/post/2013/11/14/Dynamic-Splash-Screens-in-WPF

您可以在加载任何内容时显示slapshScreen,或者只使用线程。

答案 2 :(得分:0)

splash.xaml

<UserControl x:Class="IS.Pages.Home"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" Foreground="White"
         d:DesignHeight="660" d:DesignWidth="1080" >
<Grid Style="{StaticResource ContentRoot}"  Opacity="0.5">
    <ScrollViewer Margin="0,0,0,-10">
        <Grid >

            <TextBlock FontSize="60" x:Name="OpenTime" Margin="200,100,200,400" TextAlignment="Center" TextWrapping="Wrap" />
            <Grid x:Name="LayoutRoot" Background="Transparent" 
       HorizontalAlignment="Center" VerticalAlignment="Center">

                <Grid.RenderTransform>

                    <ScaleTransform x:Name="SpinnerScale" 
                             ScaleX="1.0" ScaleY="1.0" />

                </Grid.RenderTransform>

                <Canvas RenderTransformOrigin="0.5,0.5" 
               HorizontalAlignment="Center" 
                VerticalAlignment="Center" 
                Width="120" Height="120" >

                    <Ellipse Width="21.835" Height="21.862" 
                     Canvas.Left="20.1696" 
                     Canvas.Top="9.76358" 
                     Stretch="Fill" Fill="Black" 
                    Opacity="1.0"/>

                    <Ellipse Width="21.835" Height="21.862" 
                     Canvas.Left="2.86816" 
                    Canvas.Top="29.9581" Stretch="Fill" 
                     Fill="Black" Opacity="0.9"/>
                    <Ellipse Width="21.835" Height="21.862" 
                     Canvas.Left="5.03758e-006" 
                     Canvas.Top="57.9341" Stretch="Fill" 
                     Fill="Black" Opacity="0.8"/>
                    <Ellipse Width="21.835" Height="21.862" 
                     Canvas.Left="12.1203" 
                    Canvas.Top="83.3163" Stretch="Fill" 
                     Fill="Black" Opacity="0.7"/>
                    <Ellipse Width="21.835" Height="21.862" 
                     Canvas.Left="36.5459" 
                     Canvas.Top="98.138" Stretch="Fill" 
                     Fill="Black" Opacity="0.6"/>
                    <Ellipse Width="21.835" Height="21.862" 
                     Canvas.Left="64.6723" 
                     Canvas.Top="96.8411" Stretch="Fill" 
                     Fill="Black" Opacity="0.5"/>

                    <Ellipse Width="21.835" Height="21.862" 
                     Canvas.Left="87.6176" 
                     Canvas.Top="81.2783" Stretch="Fill" 
                     Fill="Black" Opacity="0.4"/>
                    <Ellipse Width="21.835" Height="21.862" 
                     Canvas.Left="98.165" 
                     Canvas.Top="54.414" Stretch="Fill" 
                     Fill="Black" Opacity="0.3"/>
                    <Ellipse Width="21.835" Height="21.862" 
                     Canvas.Left="92.9838" 
                    Canvas.Top="26.9938" Stretch="Fill" 
                    Fill="Black" Opacity="0.2"/>

                    <Ellipse Width="22" Height="22" 
                Canvas.Left="71" Stretch="Fill" 
                  Fill="Black" Opacity="0.1" Canvas.Top="7"/>

                    <Canvas.RenderTransform>

                        <RotateTransform x:Name="SpinnerRotate" 
                                 Angle="0" />

                    </Canvas.RenderTransform>

                    <Canvas.Triggers>

                        <EventTrigger RoutedEvent="ContentControl.Loaded">

                            <BeginStoryboard>

                                <Storyboard>

                                    <DoubleAnimation 
                                Storyboard.TargetName
                                  ="SpinnerRotate" 
                               Storyboard.TargetProperty
                                    ="(RotateTransform.Angle)" 
                                 From="0" To="360" 
                                 Duration="0:0:1" 
                                 RepeatBehavior="Forever" />

                                </Storyboard>

                            </BeginStoryboard>

                        </EventTrigger>

                    </Canvas.Triggers>

                </Canvas>

            </Grid>
            <TextBlock Foreground="White" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Panora Supermarket" VerticalAlignment="Top" Width="375" Height="50"/>

        </Grid>

    </ScrollViewer>

</Grid>

将以下代码添加到splash.xaml.cs类

的构造函数中
try
        {
            Task.Delay(2000).ContinueWith(_ =>
            {
                var frame = NavigationHelper.FindFrame(null, this);
                frame.Source = new Uri("../Pages/Login.xaml", UriKind.Relative);

            });
        }catch(Exception ee){

        }

将此代码添加到启动页面,然后您可以导航到另一个页面