Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Enhancement] Automatically resize the popup depending on the content #937

Closed
1 of 2 tasks
acaliaro opened this issue Feb 18, 2021 · 7 comments
Closed
1 of 2 tasks
Labels
a/popup feature-request A request for a new feature. needs-approval Feature request has been submitted but is awaiting final approval. Please do not implement before!

Comments

@acaliaro
Copy link

Summary

Currently the Popup has its own dimension independent of the content; for example, on Android the popup almost completely fills the height of the screen. It would be useful if the popup could resize according to the content so as to take up as little space as possible on the display.

API Changes

I am not sure which APIs to use for this request. In my opinion, what I requested could be the default: if instead there is the need to have dimensions other than the minimum required by the content, the programmer can use the "Size" property to modify them.
If instead you want to keep the current default, you could use a new bool "Autosize" property which, if set to true, resizes the popup with respect to the content

Intended Use Case

If you wanted to replace the DisplayAlert method with the Popup to display a simple title, a message with an "ok" or "ok" and "cancel" button, having a popup that resized itself according to the length of the message would be very useful

Who Will Do The Work?

  • I am willing to take this on myself
  • Just putting this out there for someone to pick up
@acaliaro acaliaro added feature-request A request for a new feature. needs-approval Feature request has been submitted but is awaiting final approval. Please do not implement before! labels Feb 18, 2021
@acaliaro
Copy link
Author

#990

@Brosten
Copy link

Brosten commented May 1, 2021

This would be great to have!

@jfversluis
Copy link
Member

I think a lot of people want this, not sure how easy it is to implement though

@brminnick
Copy link
Contributor

Thanks! However, we are no longer adding new features to Xamarin Community Toolkit, focusing on the .NET MAUI Community Toolkit.

Please open a New Feature Discussion to implement this feature in the .NET MAUI Community Toolkit.

I've posted more information about the Future Of Xamarin Community Toolkit here: https://devblogs.microsoft.com/xamarin/the-future-of-xamarin-community-toolkit/?WT.mc_id=mobile-0000-bramin

@radoczsanyi
Copy link

Hello!

If someone still facing this, I did the following workaround in my application:
Since I was using grid it has the option to set the Row/Column definitions height or width to auto (but it is also works with fixed sizes).

Once you set these sizes use this code in the Popup page constructor:

this.Size = new Xamarin.Forms.Size(300, this.YourElement0.Height + this.YourElement1.Height + this.YourElement2.Height);

I'm using const value for width but it also works at the same way.

@kelltom
Copy link

kelltom commented May 3, 2023

Hello!

If someone still facing this, I did the following workaround in my application: Since I was using grid it has the option to set the Row/Column definitions height or width to auto (but it is also works with fixed sizes).

Once you set these sizes use this code in the Popup page constructor:

this.Size = new Xamarin.Forms.Size(300, this.YourElement0.Height + this.YourElement1.Height + this.YourElement2.Height);

I'm using const value for width but it also works at the same way.

My Popup page looks something like this:

<ScrollView>
    <Grid x:Name="MainContentGrid" RowDefinitions="auto, auto, auto">
        ...

And in my constructor, I did this, which seems to work:

public MyPopup()
{
    InitializeComponent ();
    BindingContext = this;
    Size = new Size(300, MainContentGrid.Height + MainContentGrid.Height);
}

Strangely, it does not work properly unless I add that 2nd MainContentGrid.Height to the height calculation. If I only have Size = new Size(300, MainContentGrid.Height), the popup takes the entire height of the screen.

I don't really understand this though. When debugging, the value of MainContent.Height is -1. That as the long value for the Size property's height causes problems. So why is -2 an acceptable value for wrapping content?

EDIT: If there is too much content inside the grid, it will overflow on the page.

@andyzukunft
Copy link

andyzukunft commented Jul 25, 2023

I just want to provide some information as @kelltom gave me some idea. I am working with Android, have to test this for iOS later on.

I had a Popup which was scaling semi-correclty. Meaning: it was scaling however long-ish label texts did not work properly. I changed the Popup Size height from 0 to -1:

Previous configuration, not fully working:
RelativeMediumWithNoFixedHeight = new(0.7 * (DeviceDisplay.Current.MainDisplayInfo.Width / DeviceDisplay.Current.MainDisplayInfo.Density), 0);

New size configuration, working with larger label texts
RelativeMediumWithNoFixedHeight = new(0.7 * (DeviceDisplay.Current.MainDisplayInfo.Width / DeviceDisplay.Current.MainDisplayInfo.Density), -1);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/popup feature-request A request for a new feature. needs-approval Feature request has been submitted but is awaiting final approval. Please do not implement before!
Projects
None yet
Development

No branches or pull requests

7 participants