如何将初始屏幕与登录窗口和主窗口链接

  • 本文关键字:窗口 登录 链接 屏幕 c# wpf
  • 更新时间 :
  • 英文 :


我有一个WPF应用程序,其中包含以下三个分离的东西:

  • 初始屏幕
  • 登录窗口
  • 主窗口

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

您可以使用

SplashScreen class执行此操作。 您必须在两个窗口的构造函数中显示/隐藏初始屏幕。

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

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

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

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){
        }

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

最新更新