Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RelativeLayout renders blank with no visible elements #21395

Open
jankovicl opened this issue Mar 22, 2024 · 0 comments
Open

RelativeLayout renders blank with no visible elements #21395

jankovicl opened this issue Mar 22, 2024 · 0 comments
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter layout-relative migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 platform/iOS 🍎 t/bug Something isn't working
Milestone

Comments

@jankovicl
Copy link

Description

When the app opens to the page with the relative layout, the entire page is blank. We tried using AbsoluteLayouts and we don't appear to have this issue although we would have to recalculate the positions of everything in our app if we had to switch them.

image

Steps to Reproduce

  1. Create a new .NET MAUI App
  2. Add a ContentPage that creates an Image and Button and adds them to a RelativeLayout.
var layout = new Microsoft.Maui.Controls.Compatibility.RelativeLayout();

var image = new Image
{
    StyleId = "LoginLogo",
    VerticalOptions = LayoutOptions.Center,
    Aspect = Aspect.AspectFit,
    Source = "logo.png"
};

loginButton = new Button
{
    StyleId = "LoginButton",
    TextColor = Colors.White,
    BackgroundColor = Colors.Blue,
    HeightRequest = 40,
    FontSize = 17
};
loginButton.SetBinding(VisualElement.BackgroundColorProperty, "LoginButtonColor");
loginButton.SetBinding(Button.CommandProperty, "Login");
loginButton.SetBinding(Button.TextProperty, "LoginButtonText");

var labelHeight = Constraint.RelativeToParent(p => p.Height * 4.2 / 62);
var labelWidth = Constraint.RelativeToParent(p =>
{

    return p.Width * .9;
});

var labelX = Constraint.RelativeToParent(p =>
{

    return p.Width * .05;
});

layout.Children.Add(image,
    Constraint.RelativeToParent(p => (p.Width - (p.Width * (27.5 - 8) / 36)) / 2),
    Constraint.RelativeToParent(p => p.Height * 3.5 / 62),
    Constraint.RelativeToParent(p => p.Width * (27.5 - 8) / 36),
    Constraint.RelativeToParent(p => p.Height * (26 - 2.5) / 62));

layout.Children.Add(loginButton,
    labelX,
    Constraint.RelativeToParent(p => p.Height * 51 / 62),
    labelWidth,
    Constraint.RelativeToParent(p => p.Height * 5 / 62));
  1. Add that RelativeLayout as the content of a ScrollView and Assign that to the Content of the ContentPage.
this.Content = new ContentView
{
    StyleId = "LoginContentView",
    Content = new Microsoft.Maui.Controls.ScrollView
    {
        StyleId = "LoginScrollView",
        Content = layout
    }
};
  1. Change the App.xaml.cs MainPage to this new ContentPage.

I created a public repo with all the files that sample what we have in our app.

Link to public reproduction project repository

https://github.com/jankovicl/MauiRelativeLayoutBug

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

No response

@jankovicl jankovicl added the t/bug Something isn't working label Mar 22, 2024
@PureWeen PureWeen added migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert layout-relative labels Mar 22, 2024
@PureWeen PureWeen added this to the Backlog milestone Mar 22, 2024
@Eilon Eilon added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter layout-relative migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants