c# - Windows 10 UWP 中的扩展启动画面?

标签 c# uwp windows-10 splash-screen

我使用以下 XAMLC# 代码为 Windows 10 UWP 应用程序创建了一个扩展启动画面。

XAML 代码

<Grid Background="#036E55">
    <Canvas>
        <Image x:Name="extendedSplashImage" Source="Assets/620.scale-200.png"/>
    </Canvas>

    <ProgressRing Name="splashProgressRing" 
                  IsActive="True" 
                  Width="20" 
                  Height="20"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Bottom"
                  Foreground="White"
                  Margin="20">
    </ProgressRing>
</Grid>

C#代码

internal Rect splashImageRect;
    private SplashScreen splash;
    internal bool dismissed = true;
    internal Frame rootFrame;
    private double ScaleFactor;
    ApplicationDataContainer userSettings = ApplicationData.Current.LocalSettings;
    JsonDataHandler dataHandler;
    //bool isZipUpdateInProgress = false;

    public ExtendedSplashScreen(SplashScreen splashscreen, bool loadState)
    {
        this.InitializeComponent();
        Window.Current.SizeChanged += new WindowSizeChangedEventHandler(ExtendedSplash_OnResize);
        ScaleFactor = (double)DisplayInformation.GetForCurrentView().ResolutionScale/100;
        //System.Diagnostics.Debug.WriteLine("ScaleFactor - " + ScaleFactor + "/n");
        splash = splashscreen;
        if (splash != null)
        {
            splash.Dismissed += new TypedEventHandler<SplashScreen, Object>(DismissedEventHandler);

            splashImageRect = splash.ImageLocation;
            PositionImage();
            //PositionRing();
        }
        rootFrame = new Frame();
    }

    void PositionImage()
    {
        extendedSplashImage.SetValue(Canvas.LeftProperty, splashImageRect.X);
        extendedSplashImage.SetValue(Canvas.TopProperty, splashImageRect.Y);
        extendedSplashImage.Height = splashImageRect.Height / ScaleFactor;
        extendedSplashImage.Width = splashImageRect.Width / ScaleFactor;

    }


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

void ExtendedSplash_OnResize(Object sender, WindowSizeChangedEventArgs e)
    {
        // Safely update the extended splash screen image coordinates. This function will be executed when a user resizes the window.
        if (splash != null)
        {
            // Update the coordinates of the splash screen image.
            splashImageRect = splash.ImageLocation;
            PositionImage();

            // If applicable, include a method for positioning a progress control.
            PositionRing();
        }
    }

现在,如果我保持旋转模式,它工作正常,但是当我关闭它时,如果我将屏幕旋转到横向模式,那么 Logo 就会不同。我正在使用 620x300 图片。

最佳答案

你可以试试这个代码,它可能会帮助你得到你想要的结果,首先删除所有定位图像代码,只用这个试试

<Grid Background="#036E55">
        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <Image Source="Assets/620.scale-200.png" Stretch="None"/>
            <ProgressRing IsActive="True" Height="30" Width="30" Margin="0,10,0,0" Foreground="White"/>
       </StackPanel>
</Grid>

Image 和 ProgressRing 将由屏幕中心的 StackPanel 管理,Image 也不会有所不同。希望对您有所帮助。

关于c# - Windows 10 UWP 中的扩展启动画面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41547574/

相关文章:

xaml - 如何在 XAML 中的 TextBlock 末尾添加空格? (Windows 10,UWP)

c# - 谷歌地图 - 75 个标记 - DialogFragments

c# - 获取包含类的实例

c# uwp listview 完成加载项目

.net - 是否所有 UWP 应用在导航页面时都会泄漏内存?

Windows 10 上的 Java 安装程序问题

C#算法搜索两个顶点之间的所有路径

c# - Paypal SOAP API - 快速结账 - 错误 10002

visual-studio - 未找到 Visual Studio 2017 和 Windows 10 SDK 10.0.15063 _scale-100.appx

java - 如何使用WebSocket在UWP客户端和Java服务器之间进行通信?