【问题标题】:Trying To navigate From Extended splash screen to another screen in uwp尝试从扩展启动屏幕导航到 uwp 中的另一个屏幕
【发布时间】:2016-12-14 11:03:49
【问题描述】:

我正在尝试从 Extended.xaml 屏幕导航到另一个屏幕 Main.xaml。 但问题是页面卡在那里没有导航到另一个页面。如何做到这一点?任何帮助将不胜感激。

Xaml 代码:

<Grid x:Name="lcol">
    <Grid.Background>
        <ImageBrush  Stretch="Fill"
                     ImageSource="ms-appx:///Assets/Home/home_android.jpg" />
    </Grid.Background>
    <RelativePanel Grid.Row="0">
    <Image x:Name="extendedSplashImage" Source="/Assets/Home/home_android.jpg"                    
           Stretch="Uniform" Height="385" Width="690"
           RelativePanel.AlignHorizontalCenterWithPanel="True"
           RelativePanel.AlignLeftWithPanel="True"
           RelativePanel.AlignRightWithPanel="True"/>
    </RelativePanel>
</Grid>

Cs 代码:

public sealed partial class ExtendedSplash : Page
{
    internal Rect splashImageRect; // Rect to store splash screen image coordinates.
    private SplashScreen splash; // Variable to hold the splash screen object.
    internal bool dismissed = false; // Variable to track splash screen dismissal status.
    internal Frame rootFrame;

    public ExtendedSplash(SplashScreen splashscreen, bool loadState)
    {
        InitializeComponent()
        try
        {
            var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
        }
        catch (Exception ex)
        {
            Log.print(ex.StackTrace);
        }
        // Listen for window resize events to reposition the extended splash screen image accordingly.
        // This is important to ensure that the extended splash screen is formatted properly in response to snapping, unsnapping, rotation, etc...
        // Window.Current.SizeChanged += new WindowSizeChangedEventHandler(ExtendedSplash_OnResize);

        splash = splashscreen;

        if (splash != null)
        {
            // Register an event handler to be executed when the splash screen has been dismissed.
            splash.Dismissed += new TypedEventHandler<SplashScreen, Object>(DismissedEventHandler);
            // Create a Frame to act as the navigation context
            rootFrame = new Frame();
            DismissExtendedSplash();
        }
    }
    void PositionImage()
    {
        extendedSplashImage.SetValue(Canvas.LeftProperty, splashImageRect.X);
        extendedSplashImage.SetValue(Canvas.TopProperty, splashImageRect.Y);
        extendedSplashImage.Height = splashImageRect.Height;
        extendedSplashImage.Width = splashImageRect.Width;

    }
    void ExtendedSplash_OnResize(Object sender, WindowSizeChangedEventArgs e)
    {
        // Safely update the extended splash screen image coordinates. This function will be fired in response to snapping, unsnapping, rotation, etc...
        if (splash != null)
        {
            // Update the coordinates of the splash screen image.
            splashImageRect = splash.ImageLocation;
            PositionImage();
        }
    }
    // Include code to be executed when the system has transitioned from the splash screen to the extended splash screen (application's first view).
    void DismissedEventHandler(SplashScreen sender, object e)
    {
        dismissed = true;
        // Complete app setup operations here...
    }
    private void DismissExtendedSplash()
    {
        rootFrame.Navigate(typeof(MainPage));
        // Place the frame in the current Window
        Window.Current.Content = rootFrame;
    }
}

【问题讨论】:

    标签: c# xaml uwp splash-screen


    【解决方案1】:

    您可以显示 App.xaml.cs 的更多详细信息。我想你的代码写成这样的官方简单

    protected override void OnLaunched(LaunchActivatedEventArgs e)
    {
        if (e.PreviousExecutionState != ApplicationExecutionState.Running)
        {
            bool loadState = (e.PreviousExecutionState == ApplicationExecutionState.Terminated);
            ExtendedSplash extendedSplash = new ExtendedSplash(e.SplashScreen, loadState);
            Window.Current.Content = extendedSplash;
        }
    
        Window.Current.Activate();
    }
    

    您的 ExtendedSplash 代码:

    public ExtendedSplash(SplashScreen splashscreen, bool loadState)
    {
        InitializeComponent()
      try
        {
            var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
        }
        catch (Exception ex)
        {
            Log.print(ex.StackTrace);
        }
    
        splash = splashscreen;
    
        if (splash != null)
        {
            // Register an event handler to be executed when the splash screen has been dismissed.
            splash.Dismissed += new TypedEventHandler<SplashScreen, Object>(DismissedEventHandler);
            // Create a Frame to act as the navigation context
            rootFrame = new Frame();
            DismissExtendedSplash();
        }
    }
    

    您在完成初始化extendedSplash 之前执行了方法DismissExtendedSplash()。所以Window.Current.Conten是MainPage,然后你执行Window.Current.Content = extendedSplash,把MainPage替换成extendedSplash

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 2014-12-07
      • 2021-11-20
      相关资源
      最近更新 更多