59

I'm using Page as landing screen in my app. XAML looks like this:

<Grid x:Name="LayoutRoot">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="3*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="7*"/>
        </Grid.RowDefinitions>

        <Rectangle StrokeThickness="0" Fill="#FF79D2F4" Margin="0,0,0,-10" Grid.RowSpan="2"/>

        <Rectangle StrokeThickness="0" Fill="#FF1F8CC5" Margin="0,-10,0,0" Grid.Row="2" Grid.RowSpan="2"/>

        <Image Source="ms-appx:///Assets/ViewMedia/Banners/Banner_Light_Big.jpg" Grid.Row="1" Grid.RowSpan="2"/>

        <Rectangle StrokeThickness="0" Grid.Row="2" Grid.RowSpan="2">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Offset="0"/>
                    <GradientStop Color="#7F000000" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>

    </Grid>

    <StackPanel MaxWidth="300" Margin="20,35"
                HorizontalAlignment="Stretch" VerticalAlignment="Bottom">

        <Button x:Name="LoginButton" x:Uid="LoginButton" Style="{StaticResource BrandButtonStyle}" Margin="0,5"
                Click="LoginButton_Click"/>

        <Button x:Name="RegisterButton" x:Uid="RegisterButton" Style="{StaticResource BrandButtonStyle}" Margin="0,5"
                Click="RegisterButton_Click"/>

    </StackPanel>

</Grid>

I've got 3 devices on which I'm running the app:

  • Microsoft Lumia 950 XL [M]
  • Custom build PC [PC]
  • Lenovo ThinkPad Tablet 2 [T]

When running the app this page renders well on M and PC but on T Gradient and two Buttons at the bottom are not rendered at all. I don't see them but I can press Buttons and their tap event handlers will strike. But if I comment Rectangle with gradient everything is fine on all devices.

This is how the app looks on T when using gradient. No buttons. And gradient is also not visible. With gradient

This is how the app looks on T without gradient. Buttons are in place. Without gradient

And this is how it should look running on PC. Buttons and gradient are visible. This is how it should look

I don't see any errors in output when running the app. I don't know why this happens only on specific devices. Maybe this is kind of known issue?

UPDATE 1

From users feedback, I can say that this bug hits only Atom-powered devices. But I'm not sure if this is 100% true for all Atom-powered devices.

UPDATE 2

I'd updated T with W10 from Insider Preview Fast Ring. The bug is in place. So this is not connected to OS builds.

UPDATE 3

Switching Buttons Style back to normal does not solve this. So Style is good, it's not the cause.

Udara Abeythilake
  • 1,215
  • 1
  • 20
  • 31
khamitimur
  • 1,078
  • 13
  • 22
  • Is BrandButtonStyle doing anything fancy? I'm still curious how you're getting those waves and stuff haha I kind of want to pick apart your layout. :) – Chris W. Mar 01 '16 at 19:38
  • @ChrisW. changing buttons Style to default one doesn't help. – khamitimur Mar 01 '16 at 19:50
  • Oh, dude, specify an actual start color for your first gradient stop even if there's no color. Try swapping `` with `` or `Transparent` or `{x:Null}` just something to provide a value of start to stop of the offset. – Chris W. Mar 01 '16 at 20:40
  • Are you sure you have the same Windows 10 build on both computers? Could one of them be using an insider build? – Kevin Gosse Mar 02 '16 at 07:40
  • @ChrisW. default value for color is #00000000. So there is no problem with it. – khamitimur Mar 02 '16 at 12:44
  • @KooKiz, PC and phone are on Insider Fast builds. tablet is on regular builds. I will update tablet with insider builds later to see I this is causing tis issue. – khamitimur Mar 02 '16 at 12:46
  • @KooKiz, as it turns out W10 build is not caused this issue. Checked on PC on regular build and updated tablet to insider fast - issue is in place. – khamitimur Mar 07 '16 at 09:29
  • @khamitimur you havent provided the main code of `StaticResource BrandButtonStyle` the issue occurs on your button Style and the code you have provided are for background page. Also try changing your StackPanel HorizontalAlignment ` ....' – Jerin Mar 17 '16 at 04:19
  • @Jerin event I use default `Style` for button this issue is in place. I don't see any reason why changing `HorizontalAlignment` will help. And it didn't. – khamitimur Mar 17 '16 at 12:04
  • It would help because if you look at current code in designer then it would align those two buttons to left initially than align it tom center. the thing is `{StaticResource BrandButtonStyle}` isnt a predefined style but a custom style instead. I wanted to check if the issue is caused due to default theme being changed on your tablet by any chance. – Jerin Mar 17 '16 at 12:29
  • @Jerin, I mean I used default `Style`. same issue with it. And why with `HorizontalAlignment` it will align `Button`s to left side and then to center? – khamitimur Mar 17 '16 at 14:19
  • @khamitimur here is the [your code](https://onedrive.live.com/redir?resid=72A2505C9C6FA57C!4891&authkey=!AEQfjAupx557gH8&v=3&ithint=photo%2cpng) on resized window now compare this with [Horizontal Alignment=Center](https://onedrive.live.com/redir?resid=72A2505C9C6FA57C!4890&authkey=!ADHpaRlxzXuRXBA&v=3&ithint=photo%2cpng). You will find your code to be more left aligned than center. – Jerin Mar 18 '16 at 04:32
  • @Jerin, I tooked care of it in `Style`. `Button`s are alighned as `Stretch`. – khamitimur Mar 18 '16 at 09:48
  • If you change `` to `` Will you still not be able to see the buttons? – G.Y Mar 18 '16 at 14:21
  • @G.Y, nope. same issue with. – khamitimur Mar 18 '16 at 18:21
  • And if you remove everything else and just keeping the buttons with the stackpanel? same issue?? still not see buttons?? if so, can I assume that the problem is actually wider than that specific app and meaning that buttons will not show at all with lenovo thinkpad? is that a correct assumption? is that a fact? – G.Y Mar 18 '16 at 18:46
  • @G.Y, as I said, If I remove `Rectangle` with gradient everuthing is alright. I can not test this on wider range of devices but for now it looks like only Atom powered devices are having this issue. – khamitimur Mar 18 '16 at 21:27
  • Is this possibly an issue with the placement in the LayoutRoot-Grid? You could try if it works when you move the buttons into the same Grid Cell as the Rectangle which causes the issue (into the inner Grid). I'm more thinking of how one could work around that issue - as going by your data this seems like a bug. – Oliver Ulm Mar 22 '16 at 06:12
  • Is there any reason why the `StackPanel`, that contains the `Button`s, is the only component that does not belong to the same `Grid` as the other components ? And have you tried to move the mentioned `StackPanel` to the same `Grid` cell as the one of the `Rectangle` that contains the gradient ? – jsanalytics Mar 28 '16 at 19:34
  • Just an idea, but maybe it's the behavior of rendering in WPF. There is a know issus in Win8.1 where you have to disable hardware rendering like this in code: RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; https://blogs.msdn.microsoft.com/jgoldb/2010/06/22/software-rendering-usage-in-wpf/ – Smartis has left SO again Mar 29 '16 at 21:17
  • @Smartis: Does UWP/WinRT use the same rendering engine as WPF? RenderOptions is WPF-only. – BoltClock Apr 04 '16 at 17:21

4 Answers4

1

Try removing the Grid.RowSpan="2" from the Rectangle (or add a RowDefinition), you have 4 rows (4 RowDefinition) but with the Rectangle having Grid.RowSpan=2 it adds up to 5 rows, so it might be causing you trouble.

EDIT: My bad, Rectangle actually spans over rows 2 and 3 (Grid.Row="2"), so it's ok.

Since you're just stacking <StackPanel> over <Grid> (with nothing fancy), you could try to replace the root layout <Grid x:Name="LayoutRoot"> with <Canvas x:Name="LayoutRoot"> and see if that makes a difference.

Yoav Aharoni
  • 2,672
  • 13
  • 18
0

I've come across similar issues, and went for a different and more portable approach.

I made a gradient image of height 1 (to save space), and sufficient pixels in width to give the proper gradient resolution. Added an image and stretched it. Quite a bit faster and offloads the renderling pipeline as well.

And it works just as well in Xamarin.Forms.

Robin
  • 616
  • 3
  • 9
0

The fact that the rectangle has a gradient in it is a probably a "red herring".

Focus first on why the buttons don't appear at all. Once you solve that, it should be easy to add the gradient.

There are two likely reasons:

  1. Adding the rectangle pushes the buttons down offscreen.

or 2. The renderer "choked" on the gradient, and didn't render anything else after it encountered it.

IMHO, #1 is more likely. I say that because I notice your overlaid StackLayout has VerticalAlignment="Bottom". So if the layout engine has (mistakenly?) decided that the single cell in the outermost grid is much taller than the screen, then two things will happen: the gradient will be stretched very far vertically (so appears not to change), and the buttons will be pushed off the bottom of the screen.

#2 would be a renderer bug involving gradient (but I doubt that will be the case).


back to #1:

What is the actual pixel height of "Banner_Light_Big.jpg"? Consider making a smaller version for the device giving you trouble [picking a version based on device height in inches or in pixels, not sure which applies here]. If you remove the banner completely, does the problem go away? If so, but you don't want to shrink it, you might need to override layout (measure?) method and do your own calculation.

Alternatively, change the two "Auto" heights to "NN*" or "NN" (NN = any specific number): anything with no "Auto"s will almost surely eliminate the problem.

If the resulting "non-Auto" layout isn't exactly what you want, at least it will give you a working starting point, from which to try slightly different variations on how to nest these elements, to get the desired spacing.

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
0

Try adding the color attribute and value for the first Gradient stop as well. Maybe since only a single color is specified, it takes the same color and applies throught the button.

<Rectangle.Fill>
      <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Offset="0"/> // add color attribute here
            <GradientStop Color="#7F000000" Offset="1"/>
      </LinearGradientBrush>
</Rectangle.Fill>
Gowshik
  • 320
  • 4
  • 13