-
Notifications
You must be signed in to change notification settings - Fork 41
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
Grid: RowDefinition and ColumnDefinition Constructor changes #85
base: master
Are you sure you want to change the base?
Conversation
: Windows.UI.Xaml.DependencyObject | ||
{ | ||
// vvvv | ||
RowDefinition(double height, GridUnitType type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few questions:
- If there is a difference between "*" and "*1" how are users able to set "*"? Should they set
height
to0
? - What about
GridUnitType.Auto
? Will height be ignored in that case? It has to essentially right? - Out of curiosity should
Double.NaN
be considered an error forGridUnitType.Pixel
andGridUnitType.Star
or should we do some special logic for that?
Or are this all topics that are just handled by GridLength and we should just pass the arguments and do no checking at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My assumption on behavior based on current behavior:
1: Setting it to 0* would give it 0 height. You should set the number to the fractions you want the height to be. Same as it works in Xaml.
2. We already have the static GridLength.Auto
getter (unless you use the WinUI3 alpha where it's oddly missing). If you use the type-overload, the number won't really matter.
3. I'd vote for an error here. Perhaps Auto
could allow NaN
, but would prefer consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bringing these things up! I'm not too sure if these are handled by GridLength, but I'll specify these special cases in the spec remarks.
Good catch with GridLength.Auto - I agree that the number should be ignored if you specify Auto as your GridUnitType.
As for NaN, I think an error would be most appropriate for all GridUnitTypes - if someone is calculating a NaN value for their layout, it would seem that there's some kind of larger underlying issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice subtle improvement. While probably out of scope for this PR, I'm curious if you also would consider simplifying adding a set of definitions. If I had to add 4 rows, I could merely say something like
myGrid.RowDefinitions = new RowDefinitionCollection(new GridLength(5).new GridLength(5, GridUnitType.Star), GridLength.Auto);
I realize that would also require RowDefinitions
to be settable.
An alternative would be to add an AddRange
method to it.
var grid = new Grid(); | ||
var column = new ColumnDefinition(); | ||
column.Width = new GridLength(1.0, GridUnitType.Star); | ||
grid.ColumnDefinitions.Add(column); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comparison seems a little unfair. These 4 lines could be written as:
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1.0, GridUnitType.Star) });
That makes it almost identical to the new syntax (just not using the new proposed constructor)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If one uses C#, you can write that. In C++ you don't have that C# syntactic sugar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points. It's true that you don't get the same kind of syntactic sugar in C++, but also I was mainly writing the sample out in this way so it makes sense with the steps that I listed above:
- Create a Column or RowDefinition object with the blank constructor.
- Define a GridLength object with the desired value for the Height or Width property of the Row/ColumnDefinition.
- Assign the GridLength object to the Height or Width property of the Row/ColumnDefinition.
Thanks @dotMorten! I like this idea. I think that changing RowDefinitions to be settable might be too big of a change for the scope of this change (might open up a whole other can of worms), but adding an AddRange method to RowDefinitions seems like a simple and very useful change. It would be a seemingly simple API update to add that method... @MikeHillberg do you think adding an AddRange() method to RowDefinitions and ColumnDefinitions would pose any issues? |
No description provided.