2017-01-09 34 views
1

Windows 10 UWPアプリ用の拡張スプラッシュ画面を、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(); 
     } 
    } 

は今、それが正常に動作しますが、私はそれをオフにするとき、私は風景モードに画面を回転させた場合ロゴは異なります。私は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で管理します、それはあなたが望むように、結果を取得するためにあなたを助けるかもしれない、このコードを試すことができますImageも変わらないでしょう。それがあなたを助けることを願っています。

+0

このモードは、モバイルアプリとデスクトップアプリの両方で動作しますか? –

+0

はい、汎用アプリでサポートされます。電話アプリやデスクトップ/タブレットアプリに必要なサイズに応じて、ImageのサイズやProgressRingのサイズを変更できます。 しかし、それは自動的に管理する薬を変更する必要はありません。 – jigar

+0

これは期待どおりに動作しません。画像は非常に大きなサイズで表示されます。 –

関連する問題