2017-01-09 68 views
1

我使用以下XAMLC#代碼爲Windows 10 UWP應用程序創建了一個擴展啓動屏幕。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(); 
     } 
    } 

現在,它工作正常,如果我繼續旋轉模式上,但是當我將其關閉,如果我旋轉屏幕爲橫向模式那麼標誌不同。我正在使用620x300圖片。

回答

3

您可以使用此代碼嘗試它可以幫助你得到結果,只要你想,首先刪除所有定位圖像的代碼只有用這種

<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> 

圖像嘗試ProgressRing將StackPanel的在屏幕中心管理並且圖像也不會有區別。希望它能幫助你。

+0

此功能是否適用於這兩種模式以及移動和桌面應用程序? –

+0

是的,它會支持通用的應用程序。您可以更改圖像和ProgressRing的大小,具體取決於手機應用程序和桌面/平板電腦應用程序的大小。 但是你不需要改變它會自動管理的魔藥。 – jigar

+0

這不按預期工作。圖像顯示非常大。 –