C# Windows10UWP中的扩展启动屏幕?

C# Windows10UWP中的扩展启动屏幕?,c#,uwp,windows-10,splash-screen,C#,Uwp,Windows 10,Splash Screen,我使用以下XAML和C#代码为windows10uwp应用程序创建了一个扩展的启动屏幕 XAML代码 <Grid Background="#036E55"> <Canvas> <Image x:Name="extendedSplashImage" Source="Assets/620.scale-200.png"/> </Canvas> <ProgressRing Name="splashProgre

我使用以下
XAML
C#
代码为
windows10uwp
应用程序创建了一个扩展的启动屏幕

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#代码

internalrect-splashImageRect;
私人飞溅屏幕;
内部布尔值=真;
内部框架根框架;
私有双尺度因子;
ApplicationDataContainer userSettings=ApplicationData.Current.LocalSettings;
JsonDataHandler-dataHandler;
//bool isZipUpdateInProgress=false;
公共扩展SplashScreen(SplashScreen SplashScreen,bool loadState)
{
this.InitializeComponent();
Window.Current.SizeChanged+=新的windowsizechangedventhandler(ExtendedSplash\u OnResize);
ScaleFactor=(双精度)DisplayInformation.GetForCurrentView().ResolutionScale/100;
//System.Diagnostics.Debug.WriteLine(“ScaleFactor-”+ScaleFactor+”/n);
飞溅=飞溅屏幕;
如果(飞溅!=null)
{
splash.disposed+=新类型的Deventhandler(DismissedEventHandler);
splashImageRect=splash.ImageLocation;
位置图像();
//定位环();
}
rootFrame=新框架();
}
void PositionImage()
{
extendedSplashImage.SetValue(Canvas.LeftProperty,splashImageRect.X);
extendedSplashImage.SetValue(Canvas.TopProperty,splashImageRect.Y);
extendedSplashImage.Height=splashImageRect.Height/ScaleFactor;
extendedSplashImage.Width=splashImageRect.Width/ScaleFactor;
}
空环()
{
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(对象发送器,WindowSizeChangedEventArgs e)
{
//安全地更新扩展启动屏幕图像坐标。当用户调整窗口大小时,将执行此功能。
如果(飞溅!=null)
{
//更新启动屏幕图像的坐标。
splashImageRect=splash.ImageLocation;
位置图像();
//如果适用,包括一种定位进度控制的方法。
定位环();
}
}

现在,如果我保持旋转模式打开,它可以正常工作,但是当我关闭它,如果我将屏幕旋转到横向模式,那么徽标就不同了。我正在使用
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>


图像和进程将通过屏幕中央的StackPanel进行管理,并且图像不会有所不同。希望它能对您有所帮助。

这在两种模式以及移动和桌面应用程序中都有效吗?是的,它将在通用应用程序中提供支持。您可以根据手机应用程序和桌面/平板电脑应用程序所需的大小更改图像和进程的大小。但你不必改变它将自动管理的药剂。这不是预期的效果。图像显示的大小非常大。图像显示的大小将与图像显示的大小相同,对于手机,您可以通过在code
if(Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily==“Windows.Mobile”){//code for phone}else{//other code}中添加条件来调整图像大小
一个小提示:如果每个比例因子都有资产,只需按如下方式设置源:
source=“ms-appx:///Assets/620.png“
。这将自动选择具有设备所需比例因子的图像。
<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>