Hello, I would like to know how I can apply a height to a minimum since the MinimumHeightRequest stackLayout property does not work
One thing I noticed from your code is that you are running Xamarin.Forms 1.0. You may wish to upgrade to 1.2.2.
But back to your question: Actually, it is working as designed. I think that the wording of the property is a little misleading. Here is how it actually works:
A test is performed between the actual height of the element and the MinimumHeightRequest property. The value which is lowest, is the one that get selected.
In your example the height of the label is 27 and you MinimumHeightRequest is 200, so the calculation looks like this:
var newMinheight = Min(label.Height, label.MinimumHeightRequest)
And the result is 27, which is what your label height ends up being.
Is there a reason you just cannot use HeightRequest instead of MinimumHeightRequest?
Finally, you're putting a stack layout inside of a grid. You need to be careful how both are constructed because you can end up with some very interesting results if you are not careful.
Answers
What exactly does your
StackLayout
look like?there I send you an example I am using the MinimumHeightRequest:
File: WindowPopup.cs
Line: 83
Good day, I wonder if you have seen the example to see that does not work.
Thank you
One thing I noticed from your code is that you are running Xamarin.Forms 1.0. You may wish to upgrade to 1.2.2.
But back to your question: Actually, it is working as designed. I think that the wording of the property is a little misleading. Here is how it actually works:
A test is performed between the actual height of the element and the MinimumHeightRequest property. The value which is lowest, is the one that get selected.
In your example the height of the label is 27 and you MinimumHeightRequest is 200, so the calculation looks like this:
And the result is 27, which is what your label height ends up being.
Is there a reason you just cannot use HeightRequest instead of MinimumHeightRequest?
Finally, you're putting a stack layout inside of a grid. You need to be careful how both are constructed because you can end up with some very interesting results if you are not careful.
Is there a reason you just can not use HeightRequest instead of
MinimumHeightRequest?
My intention is to create a windowpoup that when there will be if the content of the window is less than a minimum is created with the minimum
're putting a stack inside of a grid layout.
Within a cell of a grid I could not put a stackLayout?
Thanks for your answers.
yes, you can put a StackLayout inside of a grid (which is how most of us do it, I think). The only issue you have to watch out for is the sizing of the cells vs. the sizing of the contents.
Excuse my ignorance, as I really am new issue Xamarin.
I did not understand means StackLayoutSize <= cellsize?
Thanks again and sorry for the inconvenience.
This should NOT be designed this way. If I set HeightRequest = X, I am requesting the height to be X tall assuming the layout container can accommodate it. Similarly, if I set MinimumHeightRequest = Y, I am requesting the height to be NO SMALLER than Y assuming the layout container can accommodate it.
The calculation should be:
It should be the MAX of the two values, not the min. I would bet 100% of developers would assume MinimumHeightRequest means "no smaller than the value I am providing".
I agree 100% with the quote above.
The current implementation of this property given its name is extremely confusing. Why not just implement it the way
min-height
works in CSS?I agree with it. Is this a pull request to solve this or a bug report ?
We also bumped into this. Looking at the code I figured that in order for the property to actually contain the minimum height request, this line should be removed:
minimum.Height = Math.Min(request.Height, minimum.Height);
Apparently MinimumHeightRequest and MinimumWidthRequest are not intended to do what us mere mortals think they should do.
I raised a bug for this a while ago at:
https://bugzilla.xamarin.com/show_bug.cgi?id=44738
The response was "While we wish Minimum Width/Height worked differently, such a change now would be a large breaking change to many users and as such will not be fixed". Personally, I reckon most people would prefer the breaking change as what it does now is not what it logically should do (and I don't actually think it would break many dev's code).
A proposal to do something about it was also rejected, details at:
https://forums.xamarin.com/discussion/84885/rejected-obsolete-minimum-width-height-request#latest
Thanks, John! The links were helpful for me because they made me realize nothing will change.
I am curious to see how one is supposed to use the min request properties, because setting them does not seem to make any difference. For what are they good? Does anybody have an example?
I don't bother because as John explained, they make no difference. Where possible I use grids and percentage sizing to try and make the UI as device friendly as possible...bit tricky sometimes though in certain scenarios.
Again... and this has been my resounding response as a Veteran .NET Engineer just coming into the Mobile World and Xamarin:
I ask the Xamarin team, what kind of developers you want to focus on? Do you want a community of mostly junior/indie devs who need to be kept "safe" from themselves? Or do you want to provide a feature rich framework with conformity and standardization, that is flexible, scalable and easily considered by enterprise teams?
You are part of Microsoft now - if anything good comes of that, it should be this.
I would actually be extremely interested in seeing if anyone actually uses the current public implementation of it? Maybe a vote would be interesting.
@BradChase.2654 I can say with certainty that I've never used Minimum[X]Request ever because it just doesn't do what I want it to do.
Example
I would expect this to make the Label a minimum of 30d tall even if there is no text within. What it actually does... Nothing.
I haven't upgraded to XF 3.0 yet. Is it safe to assume Microsoft/Xamarin missed the opportunity of a major version number change to change MinimumHeightRequest and MinimumWidthRequest (either to make them do what we all want them to do, or simply to deprecate them)?