Splashscreen Rect coordinates returning Screen dimesions on Win 10 Mobile

I am trying to create an extended SplashScreen on my UWP app for which the SplashScreen image coordinates are needed. I am using the following code in App.xaml.cs:

 protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            if (e.SplashScreen != null)
                var SplashLocation = e.SplashScreen.ImageLocation;
            //Rest of initialization...
        }

However, if I inspect SplashLocation which is a Rect, SplashLocation.Height and SplashLocation.Width return 1280 and 768 which is the dimension of my phone's screen. All other properties are 0.

Is this a known bug in Win 10 Mobile [build 10536]? It works fine on desktop Windows 10.


ANSWERS:


Actually the issue is that the code given on the MSDN docs is wrong. Have a look at their samples on Github instead. You can find it here: Splash Screen Sample

Notice the differences between the MSDN docs and the sample:

  1. ExtendedSplash DOES NOT extend page
  2. They use a ScaleFactor for phone
  3. The root element of the XAML is Grid and not page.

I followed their sample (after hours of wondering) and it all worked well. I hope they update their docs to reflect the correct thing.


As a workaround, here's what I did:

Create an Image in XAML inside a Grid (and NOT inside a Canvas as suggested by the msdn Docs)

    <Image Name="ExtSplash" 
           Stretch="Uniform" 
           HorizontalAlignment="Center"  
           VerticalAlignment="Center" 
           Source="Assets/Splash/SplashScreen.png"/>

Now, the trick is to make it work on both Mobile (which doesn't give correct Rect coordinates and Desktop (which works as expected)

So, in the loaded event of Page in code behind, I used this code:

    if (splash.Top < splash.Left)
        ExtSplash.Margin = new Thickness(splash.Top);
    else
        ExtSplash.Margin = new Thickness(splash.Left);

where Splash = e.SplashScreen.ImageLocation from the OnLaunched event in App.xaml.cs.

This works because, Splash.Top and Splash.Left both return 0 in case of Mobile. So the app just displays the splashscreen fully extended to the width. In case of Desktop, the Image may have some Left or Top Coordinates as it's reported correctly on desktop, where I set them as Margin for the centrally aligned uniform stretched image.

NOTE 1: There may be cases where a slight variation may occur between splashscreen and the ExtendedSplash image. But in my testing it worked fine. It will continue to work even when in a later build MS fixes the issue, so you can take your time to implement the standard method then.

NOTE 2: I had some issues with this logic if scale-400 splashscreen image was provided. For some reason WM10 picks up the highest resolution available. So I just supplied 100, 125, 150 and 200 scale images (skipped the 400)


I ended up ditching the SplashScreen.ImageLocation approach. The Microsoft tutorial does not work on mobile at the time of writing, and the sample is hackish. Instead I used a simple layout like this for the extended splash screen:

<Grid>
    <Image x:Name="splashScreenImage" Source="Assets/SplashScreen.png" MaxWidth="620" MaxHeight="300"/>
    <!-- plus some other control -->
</Grid>

The magic is to use MaxWidth/MaxHeight.

On mobile the the image will be slightly different positioned vertically (because of status bar and navigation bar I guess), but otherwise correct including size. On desktop the image seems to be exactly positioned and sized as the initial splash.



 MORE:


 ? C# - Read data in from audio jack - Universal windows 10
 ? Windows 10 Mobile (10.0.14393) Background Task for Geofence (LocationTrigger)
 ? How to maximize a UWP window (not fullscreen)
 ? How to maximize a UWP window (not fullscreen)
 ? How to maximize a UWP window (not fullscreen)
 ? How to change Border Color of TextBox on Focus in UWP
 ? How to convert string to image.source in UWP?
 ? Viewport3D not support UWP
 ? Windows 10 (UWP) manifest issue
 ? Windows 10 (UWP) manifest issue