扩展的启动画面 - ProgressRing移动设备的消费者

时间:2017-06-29 07:07:59

标签: xaml uwp windows-10 windows-10-universal windows-10-mobile

我已按照Microsoft文档制作了ExtendedSplashScreen。我在启动画面中有一个徽标和ProressRing。它在桌面上运行良好(Logo位于中心,ProgressRing位于桌面下方)。但是在我的手机上,ProgressRing消失了(可能不在视线范围内),但徽标位于中心位置。 这是我的XAML:

<Grid Background="#FFFFFF">
        <Canvas>
            <Image x:Name="extendedSplashImage" Source="/Assets/GeneraredSplash/SplashScreen.scale-100.png"/>
            <ProgressRing Name="splashProgressRing" IsActive="True" Width="20" HorizontalAlignment="Center"/>
        </Canvas>
    </Grid>

代码:

namespace Project.Views
{
    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();
            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);
                // Retrieve the window coordinates of the splash screen image.
                splashImageRect = splash.ImageLocation;
                PositionImage();
                // Optional: Add a progress ring to your splash screen to show users that content is loading
                PositionRing();
            }
            // Create a Frame to act as the navigation context
            rootFrame = new Frame();
        }

        // Position the extended splash screen image in the same location as the system splash screen image.
        void PositionImage()
        {
            double ScaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

            extendedSplashImage.SetValue(Canvas.LeftProperty, splashImageRect.Left);
            extendedSplashImage.SetValue(Canvas.TopProperty, splashImageRect.Top);

            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
            {
                extendedSplashImage.Height = splashImageRect.Height / ScaleFactor;
                extendedSplashImage.Width = splashImageRect.Width / ScaleFactor;
            }
            else
            {
                extendedSplashImage.Height = splashImageRect.Height;
                extendedSplashImage.Width = splashImageRect.Width;
            }
        }

        void PositionRing()
        {
            double ScaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

            splashProgressRing.SetValue(Canvas.LeftProperty, splashImageRect.X + (splashImageRect.Width * 0.5) - (splashProgressRing.Width * 0.5));
            splashProgressRing.SetValue(Canvas.TopProperty, (splashImageRect.Y + splashImageRect.Height + splashImageRect.Height * 0.1));

            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
            {
                splashProgressRing.Height = splashProgressRing.Height / ScaleFactor;
                splashProgressRing.Width = splashProgressRing.Width / ScaleFactor;
            }
        }

        //Other methods like DismissExtendedSplash(), DismissedEventHandler(), ExtendedSplash_OnResize(Object sender, WindowSizeChangedEventArgs e).....
    }
}

我对图像缩放,RawPixels,ScaleFactor等不太熟悉。 我找到了代码here

另外,如果你们知道一些关于启动画面的好教程或类似的东西(微软文档除外)可以提供帮助,请发布链接。

1 个答案:

答案 0 :(得分:0)

您应该将ProgressRing控件放在Grid中。它应始终位于页面的中心,而不是任何孩子的中心。

同样HorizontalAlignment="Center"在Canvas中不做任何事情。您需要使用 Canvas.Left Canvas.Top