-
Notifications
You must be signed in to change notification settings - Fork 678
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
Feature Proposal: Make Grid Better #54
Comments
I assume in this that Grid.AutoFill maps to CSS grid's grid-auto-flow? (I stumbled on the name change at first) |
I'm curious about this part of the Defining Named Areas example: ...
<AreaDefinition Name="imageArea" Row="toprow,bottomrow" Column="0"/>
...
<Image Grid.Area="imageArea"/>
... How would the image be displayed in an area that covers multiple rows? (or equivalent for columns?) Non-sequential rows or columns in an |
+1 for being able to name rows and columns. I can see this being a great way to improve the readability of code. |
To add clarity to the Auto-fill Layout w/ Autogenerated Rows (or Columns) example, is this equivalent ? <Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="240" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition MinHeight="80" Height="Auto" />
<RowDefinition MinHeight="80" Height="Auto" />
<RowDefinition MinHeight="80" Height="Auto" />
</Grid.RowDefinitions>
<Grid.Resources>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
</Grid.Resources>
<TextBlock Text="Id" Grid.Column="0" Grid.Row="0" />
<TextBox x:Name="IdField" Grid.Column="1" Grid.Row="0" />
<TextBlock Text="Name" Grid.Column="0" Grid.Row="1" />
<TextBox x:Name="NameField" Grid.Column="1" Grid.Row="1" />
<TextBlock Text="Address" Grid.Column="0" Grid.Row="2" />
<TextBox x:Name="AddressField" Grid.Column="1" Grid.Row="2" />
</Grid> |
@chrisglein Yes, the autofill would behave the same as the CSS Grid's auto-flow. @mrlacey The intention with Row="toprow,bottomrow" was that it be interpreted as a range "from,to" rather than a set of non-contiguous rows/columns. I'll clarify that in the proposal. I considered using a colon as the delimiter like Excel, but went with comma for now. |
A comma is used as a separator elsewhere in this proposal so a colon to indicate a range sounds better. |
Define the undefined behaviorsXAML's Grid is the most widely used Panel and is very versatile. However, there are some undefined behaviors. I hope we can define undefined behaviors. Reading Tips: All of the examples described in this article are not common usages for Star Unit on Infinite spaceCopy and paste the code below and run to view the result: <Canvas>
<Grid Height="100">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="CornflowerBlue" Width="150" />
<Border Grid.Column="1" Background="Tomato" Width="150" />
<Border Grid.Column="2" Background="Teal" Width="150" />
</Grid>
</Canvas> See Scenario1 in demo. The 1st column is Did you predicate the result? Although the 2nd and the 3rd column width proportion is 1:2, the final visible proportion is 1:1. There are flaws here, because you may suspect that the 3rd column is already twice as much as the 2nd column, but the right side is blank and cannot be seen. So now, we remove the <Grid HorizontalAlignment="Right">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="CornflowerBlue" Width="150" />
<Border Grid.Column="1" Background="Tomato" Width="150" />
<Border Grid.Column="2" Background="Teal" Width="150" />
</Grid> See Scenario2 in demo. After running, you will find that there is no white space on the far right, that is to say, the 2nd and 3rd columns do not have a 1:2 ratio - they are equal. So where is the lost space? Let's resize the window to check it. Even if there is space left on the left, the right side begins to clip the element space! Can we say that the length of a missing * length has gone to the left? Obviously not. However, we can guess that the clipping of the right side of the element begins at the 1:2 ratio. Star Unit at the Size Just Required
Now, we modify the 2nd column <Grid HorizontalAlignment="Right">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="CornflowerBlue" Width="150" />
<Border Grid.Column="1" Grid.ColumnSpan="2" Background="Tomato" Width="150" />
<Border Grid.Column="1" Background="Teal" Width="150" />
</Grid> See Scenario3 in demo. The new behavior did not show much surprise to us because we have seen the behavior last section. The 3rd column disappeared, and the 2nd column still lost the 1:2 ratio. Narrow the window again. Narrow the window again to view the behavior Why did the tomato If we have realized in the last post section that the right-side space is lost when it is right-aligned, why does the white space appear suddenly in the right-side again? I tried to slightly increase the width of the second The Proportion of Auto SizeNow, abandon the previous right-aligned test method and no longer use the <Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border Width="159" Grid.ColumnSpan="3" HorizontalAlignment="Center" Background="PaleGreen" />
<Border Width="28" HorizontalAlignment="Left" Background="#7FFF6347" />
<Border Width="51" Grid.Column="1" HorizontalAlignment="Center" Background="#7FC71585" />
<Border Width="28" Grid.Column="2" HorizontalAlignment="Right" Background="#7F008080" />
</Grid> See Scenario4 in demo. Specifically, we have four How are the columns in the actual layout divided? Here is the column width that the designer shows for us: Where do What if this is a calculation error? So let's look at the other two sets of values for the three In The same Element Size but Different Column WidthIn the experiment in the previous section, we notice that the same size brought about the same final visible size regardless of the proportion. However, this conclusion still can be subverted. Now, we will replace 3 columns with 4 columns, and the number of <Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border Width="159" Grid.ColumnSpan="3" HorizontalAlignment="Center" Background="PaleGreen" />
<Border Width="159" Grid.Column="1" Grid.ColumnSpan="3" HorizontalAlignment="Center" Background="PaleGreen" />
<Border Width="28" HorizontalAlignment="Left" Background="#7FFF6347" />
<Border Width="51" Grid.Column="1" HorizontalAlignment="Center" Background="#7FC71585" />
<Border Width="51" Grid.Column="2" HorizontalAlignment="Center" Background="#7FC71585" />
<Border Width="28" Grid.Column="3" HorizontalAlignment="Right" Background="#7F008080" />
</Grid> See Scenario5 in demo. Specifically, the first What is the width of the columns laid out at this time? Wait! Where did the 39 come from? If the equal-size The conclusion of the Grid undefined behaviorIn summary, the
However, you may think that I use the Microsoft does not have any official documents that disclose these bizarre behaviors, and I have not found such behavior in any third-party references (this post is my own conclusion). I think that Microsoft did not publish this kind of documents because the behaviors are too bizarre to be documented! I hope we can define this behaviors. See The undefined behaviors of WPF Grid (the so-called bugs) - walterlv |
Agree to fix that undefined grid behaviors. This may not be bugs, but it's behavior is really undescriptable. |
@lindexi A clear advantage of WinUI living here on GitHub is that we can A) have the source code for the Grid layout readily available, B) use Issues to track either incorrect behaviors or the lack of documentation for edge case behaviors. It seems like together that can help shed light on undefined behaviors and get them to be defined? @micahl framed this proposal as a desire to absorb some of the goodness from CSS's grid and make a more expressive Grid for XAML via WinUI. As interesting as the cases you've raised are, it seems like there's enough meat there to raise a separate discussion about these existing edge cases? I don't want to distract from the proposal @micahl laid out. Or at the very least phrase these edge cases in a way that are more relevant to the CSS comparison. For example, you can model that first scenario in CSS and talk about how the behavior is different between that and the XAML equivalent and how we feel about those differences:
|
IMHO a lot of the feature presented above to improve Grid, it really sounds like what you're looking for is RelativePanel. I do agree ColumnDefinitions should have a simple syntax, and that could easily be achieved with a string converter. Ie |
We also added an enhanced UniformGrid to the toolkit; so it'd be interesting to think about the overlap between those scenarios and the ones proposed here. I think the main thing the UniformGrid adds is that it's also effectively an ItemsControl that can take a collection of items to layout, which seems to be a bit what the 'AutoFill' feature is trying to accomplish as well? I guess the question is could these new Grid 'extensions' cover the UniformGrid scenarios as well? |
@michael-hawker It does seem like some of the AutoFill/AutoRows options could eliminate the need to use UniformGrid for many scenarios. I'm not sure if it covers all. So I walked through the scenarios listed in the document you linked and recreated them in CSS grid: https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/uniformgrid#grid-properties
https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/uniformgrid#sized-children
https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/uniformgrid#fixed-child-locations
https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/uniformgrid#override-rows-and-columns https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/uniformgrid#orientation Note that for many of the above examples I'm making a hard assumption about 3 columns instead of re-flowing. CSS grid seems pretty adverse to re-flowing the layout in that way, and it doesn't handle constraints in the way I expect. Again this is something that CSS flex layout does better with flex-wrap. We'd want a XAML Grid's auto flow options to be able to handle wrapping. If you have any other UniformGrid scenarios please share them. It does feel like we can achieve a superset Grid layout. |
There's a request on UserVoice to ShowGridLines that ought to be considered for this feature proposal. |
@chrisglein Isn't the Orientation behavior covered by the grid-auto-flow in CSS? An orientation of Horizontal is the same as auto-flow of row and Vertical is column? |
@micahl I was thinking of the comparison to flex-direction=row-reverse/column-reverse. CSS flex gives you the ability to reverse the order where CSS grid does not. If I'm understanding "dense" correctly it's really about sacrificing element order so that the grid can be more tightly packed. Consider the difference between "row" and "row dense" in this example:
The thing that makes that example work is having an item with a span that causes it to not fit. This mode would actually make sense in a wrapping flex layout as well (looking forward for smaller items before wrapping a larger item to the next row), but to my knowledge that doesn't exist. Which isn't what I thought "dense" was going to be at first glance (although the behavior does make sense to me). I was at first looking for a knob to control whether undesignated cells filled in at the earliest open spot or after the last filled spot. Do you fill in the middle or append at the end? Which is probably a useful option although isn't what "dense" does. |
Right. The downside to the dense behavior is that it might adversely impact an accessibility experience because of how it might jumble around the ordering. Updates to the proposal...
@mrlacey I agree that the comma for specifying a span can be confusing given how its used elsewhere. For the sake of discussion some alternatives might be:
From the perspective of readability the colon seems to blend into the text when using names as opposed to numbers which makes it less decipherable. A double-dot '..' fairs better IMO. The slash just makes me think of division. The explicit RowSpan and ColumnSpan is familiar, albeit verbose. I'm interested to hear others opinions. |
@micahl I like
|
FYI, to call out, a similar discussion was opened on the WPF Issues: dotnet/wpf#166 |
@michael-hawker Yes, I linked it already, as you can see above. Thanks for explicitly mentioned it here. @micahl Thanks for the proposal. Here some thoughts:
On the other points I agree with @dotMorten. The RelativePanel has a lot of that stuff mentioned. I think the Grid should be improved, but it should also stay straight and simple. From my point of view, we should start with the simpler syntax for RowDefinitions and ColumnDefinitions by implementing a Type Converter and we should improve the tooling. |
@thomasclaudiushuber I like the idea of areas and binding the name. I always modify the Grid's row and column when we change the UI and I need change all the element's row and column in the Grid when I insert the row or the column at the first row or the first column. If I can bind the name that I can add the row or the column without modifying the element. |
@thomasclaudiushuber I've updated the proposal to follow the current naming precedence with RowDefinitions and ColumnDefinitions (and AreaDefinitions for consistency). I agree there's ways that tooling can help in making it easier to use Grid (and other layouts) and would hope that any improvements to Grid (UWP and WPF) are complementary to any future improvements in the tooling. @diverdan92 as fyi |
@micahl So something similar to this:
|
Thanks, @trodent83. Based on your comment I took a moment to look across a few different apps using Grid to see what common patterns existed for rows/column definitions. Granted this wasn't a very rigorous data collection exercise, but my observations were that:
Assuming what I observed holds more generally and there are usually only a handful of column/row definitions (less than 3) I'd suspect that a common approach would be to just rely on the shortcut syntax for Row/ColumnDefinitions. For example: |
Add How to use?
It like the We define another set of attributes But when we use Grid.RowSpan to bind the RowSpanDefinitions, can we use Grid.Row property? |
@micahl And I thing the two aproaches could be merged relatively easy, and so we could have the best of the two worlds. |
Thanks for the suggestions! At this point in the conversation I think we need to start considering what the merge would look like if the proposed options are combined and ask ourselves, "Is the behavior for various combinations still reasonable? Does it create conflicts or duplication?" The tl:dr; answer to those is No and Yes. Let's see if we can whittle things down to make it Yes and No. @lindexi I believe AreaDefinitions can provide the same functionality as RowSpanDefinitions and ColumnSpanDefinitions. It seems reasonable to set a combination of Grid.Row/RowSpan/Column/ColumnSpan properties on an element in addition to specifying a Grid.Area. But, what would it mean and what takes precedence? I believe having the Row(Span)/Column(Span) values take precedence would make the most sense. They'd behave like overrides on the area. For example: <Grid Name="Root"
Rows="5" RowHeight="Auto"
Columns="5" ColumnWidth="Auto"
AreaDefinitions="{Name=Foo Row=1..2}, {Name=TheNext Row=1..3}">
<Rectangle Name="Back" Grid.Column="1" Grid.Area="Foo"/>
</Grid> Since the definition of the Foo area didn't explicitly set a Column it would have to use a default (i.e. zero). Explicitly setting the Grid.Column="1" in the example will mean that the Rectangle will be on row 1 spanning to row 2 and end up in column 1 (instead of the default column 0). Taking this exploration a bit further to consider the combinations of other properties... What would happen in the contrived example below? <Grid Name="Root"
Rows="3"
RowHeight="Auto"
RowDefinitions="{Name=BackRow Row=1}"
Columns="3"
ColumnWidth="Auto"
AutoFlow="Row"
AutoRowDefinitions="40"
AutoColumnDefinitions="60"
AreaDefinitions="{Name=BackArea1 Column=1 Row=1..3},{Name=BackArea2 Column=1 Row=BackRow},{Name=BackArea3 Column=1 Row=BackRow..6">
<Rectangle x:Name="Rect1" Grid.Column="1" Grid.Row="BackRow"/>
<Rectangle x:Name="Rect2" Grid.Column="1" Grid.Row="1..2"/>
<Rectangle x:Name="Rect3" Grid.Area="BackArea1"/>
<Rectangle x:Name="Rect4" Grid.Area="BackArea2"/>
<Rectangle x:Name="Rect5" Grid.Area="BackArea3"/>
<Rectangle x:Name="Rect6" Grid.Column="4" Grid.Area="BackArea1" Grid.Row="4"/>
<Rectangle x:Name="Rect7" Grid.Column="4" Grid.Area="BackArea3" Grid.Row="4"/>
</Grid> My initial reaction is that it can become confusing very quickly. I believe it would be something equivalent to the markup below. Some issues raised by this exercise are:
<Grid Name="Root">
<Grid.RowDefinitions>
<!-- These rows come from the Rows="3" RowHeight="Auto" properties. -->
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<!-- These are autogenerated to provide the filler rows until the actual row referenced by BackArea3. -->
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<!-- This is created so that the row referenced by Rect6 and 7 exists.
It's Auto by default to mimic what the CSS Grid seems to do. Should it be
based on the RowHeight property instead? How does RowHeight behave with
AutoRowDefinitions? -->
<RowDefinition Height="Auto"/>
<!-- These are autogenerated to provide the filler rows until the next row -->
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<!-- This is row is required to satisfy the rowspan that comes from combining
Rect7's Grid.Row with the BackArea3 area definition. The row's height is
Auto by default to mimic what the CSS Grid seems to do. Same question as
before. Should it be based on the RowHeight property instead? -->
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<!-- the first 3 Auto columns come from the Columns="3" ColumnWidth="Auto" properties -->
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<!-- the next 2 columns are autogenerated to create the fifth column (Column="4") that Rect6 and Rect7 assume to exist -->
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
</Grid.ColumnDefinitions>
<Rectangle x:Name="Rect1" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2"/>
<!-- Row=1..2 meant row 1 to row 2. It becomes row 1 with a span of 2. -->
<Rectangle x:Name="Rect2" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2"/>
<Rectangle x:Name="Rect3" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2"/>
<Rectangle x:Name="Rect4" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2"/>
<!-- Row=1..6 meant from row 1 to row 6. It becomes row 1 with a span of 5. -->
<Rectangle x:Name="Rect5" Grid.Column="1" Grid.Row="1" Grid.RowSpan="5"/>
<!-- BackArea1 had Row=1..3 which would be row 1 with a span of 2, but the
explicit Grid.Row="4" overrides the starting position (only). -->
<Rectangle x:Name="Rect6" Grid.Column="4" Grid.Row="4" Grid.RowSpan="2"/>
<!-- BackArea3 had Row=Back..6 (same as 1..6) which would be row 1 with a span of 5,
but the explicit Grid.Row="4" overrides the starting position (only) -->
<Rectangle x:Name="Rect7" Grid.Column="4" Grid.Row="4" Grid.RowSpan="5"/>
</Grid> If you made it through that and it made any sense then hats off to you. ;) |
@micahl This is my lack of consideration. I find all of my codes and I can not find any app use it. |
I came across this post talking about I don't think this is a very common scenario but could be something to have a think about. ;) |
Uncommon scenarios may be uncommon, because they are too difficult to implement with current controls and layout engines. |
Good scenario. Reading the post it reminded me of the shared sizing capability that WPF supports on its Grid which helps address that exact kind of situation. Another approach (that honestly warrants its own separate proposal for discussion) is to introduce the concept of attached layout more broadly than repeater controls. Separating the pure layout logic from the container (e.g. Panel) would allow a given layout / sizing to be shared across separate containers. <Page.Resources>
<GridLayout x:Key="sharedGridLayout" AutoFlow="Row" AutoColumnDefinitions="48,Auto"/>
</Page.Resources>
<LayoutPanel Layout="{StaticResource sharedGridLayout}">
<FontIcon/>
<TextBlock Text="Lorem"/>
<FontIcon/>
<TextBlock Text="Lorem ipsum dolor"/>
</LayoutPanel>
<!-- ... -->
<LayoutPanel Layout="{StaticResource sharedGridLayout}">
<FontIcon/>
<TextBlock Text="Lorem ipsum ..."/>
<FontIcon/>
<TextBlock Text="Lorem"/>
</LayoutPanel>
|
Amazing. I totally forgot about The other approach works even better IMO given that's mostly where we use repeated layouts. |
Just thought of something else. ;) Have we considered making
Currently, I will have to duplicate and modify the entire style if I want to change the layout of inner elements of a control. If they were bindable, I could simply override |
We have gone from XAML providing best in class Grid panels, with CSS and HTML utterly failing. To HTML CSS having a very flexible solution as well as powerful. When final decisions are made to pursue a new Grid control, I think it should be done as a new control at least until it can reach the maturity of the current Grid control. So far what @JustinXinLiu has been considering, are tweaks and simpler XAML notation for the Grid. But if this new enhanced Grid was done as a new control, more options could be considered as well as breaking changes as the expectation wont be just simply substituting one for another. Things like:
|
@micahl @jevansaks CSS Grid properties are now animatable in Firefox Nightly: I know XAML layout currently runs on the UI thread but perhaps this new Grid provides an opportunity to make fast layout transforms like this easier--even if some smoke and mirrors are required, like automatically animated clips. |
@bschoepke nice one, but I am not sure if it's a P.S. Currently we can use |
Linking issue from the toolkit, closed ours out for now as it's an open item here. For reference, here's the WPF Property for ShowGridLines for back-compat. And the UserVoice item currently has 18 votes for this property. |
What about making this enhanced Grid a CompositionGrid which moves the layout from UI Thread to the Composition Layer, and becomes flexible in how and where items will be layed out, and allows for flexible reflow as the size changes, whilst keeping it smooth, and enabling future advances like lifting elements out for Mixed Reality 3D presentation. |
Hey folks, I only recently returned from being gone since mid-January and have been catching up on things. I apologize if it seemed like I went dark. If it happens again I'll be sure to mention it beforehand or at least set my GitHub status. Good discussion and thanks for all the input! @JustinXinLiu, its interesting to think about lifting the layout out of a control such that it can be more easily styled without requiring you to re-template. For example, if a control's template parts were assigned their slot in the layout by name (i.e. Grid.Area) and if it was possible to set the Grid definitions the control should use then I believe it would make changing a control's internal layout <Style>-able. @mdtauk, moving all of layout from the UI thread to the composition layer would be pretty gnarly (in ways both good and not so good). Depending on the desired UX there might be ways to achieve it without moving everything off the UI thread. |
This proposal is rather big (albeit great), I've created a separate proposal for just a simpler string-conversion based syntax of Row and Column definitions (linked above here) that might be a good simple first-step that is very achievable to do and doesn't require a lot of new API or behavior. |
I've started a dicussion in WindowsCommunityToolkit to support dynamic layout switching in I used plain An example layout like this
could be expressed simply like below:
Complete exampleThe example defines two possible layouts for a grid and supports switching them dynamically (by setting the <Grid x:Name="RootGrid" GirdExentions.ActiveLayout="Normal">
<!-- Declaratively define the possible layouts. -->
<!-- GridExtensions.Layouts is a dictionary of GridLayoutDefinition -->
<GridExtensions.Layouts>
<GridLayoutDefinition x:Key="Normal">
<!-- A GridLayoutDefinition consists of -->
<!-- row definitions, column definitions and an area definition -->
<GridLayoutDefinition.RowDefinitions>
<RowDefinition Height="Auto"/>
</GridLayoutDefinition.RowDefinitions>
<GridLayoutDefinition.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</GridLayoutDefinition.ColumnDefinitions>
<!-- Area definition just simply puts down -->
<!-- children names in desired order -->
Number Title Description
</GridLayoutDefinition>
<GridLayoutDefinition x:Key="Narrow">
<GridLayoutDefinition.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</GridLayoutDefinition.RowDefinitions>
<GridLayoutDefinition.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</GridLayoutDefinition.ColumnDefinitions>
Number Title; <!-- semicolon is used to separate differnt rows -->
Description Description <!-- row/column span is expressed by repeating the elment name -->
</GridLayoutDefinition>
</GridExtensionstensions.Layouts>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="NarrowState">
<VisualState.StateTriggers .../> <!-- Trigger implementation omitted -->
<VisualState.Setters>
<!-- Only ActiveLayout property on the root grid needs to change according to the visual state -->
<Setter Target="RootGrid.(GridExtensions.ActiveLayout)" Value="Narrow">
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<TextBlock x:Name="Number">1</TextBlock>
<TextBlock x:Name="Title">Lorem Ipsum</TextBlock>
<TextBlock x:Name="Description">Lorem ipsum dolor sit amet...</TextBlock>
</Grid> |
Proposal: Grid - More gain, less pain
Summary
Make a version of Grid that is easier to use and manipulate with capabilities that are on par with the CSS Grid.
Rationale
XAML's Grid is the most widely used Panel and is very versatile. However, it's also one of the more complicated panels and can be cumbersome. It doesn't lend itself well to easily positioning elements or simple adjustments (e.g. inserting a new row/column). Enhancing the Grid in a few simple ways will go a long way towards easing a developer's job.
Functional Requirements
Usage Examples
Named Row / Column
A More Succinct Syntax
Defining Named Areas
Specify a single Row (or Column) using just the name or the index. You can optionally provide a span by name or relative count with the comma syntax "fromRow,toRow" or "fromRow,#".
More Succinctly Defined Areas
Auto-flow Layout w/ Auto-generated Rows (or Columns)
The AutoFlow property determines how elements that aren't explicitly assigned to an area / row / column will be placed. The default is 'None'. A value of 'Row' causes the layout to attempt to sequentially fill the columns of a row before moving to the next row. It can leave gaps by not considering if elements seen later could have fit on earlier rows.
A value of 'RowDense', however, would attempt to fill in the earlier gaps with elements seen later. RowDense can affect the visual ordering and could adversely impact accessibility. Similar behavior applies to values of Column and ColumnDense.
Detailed Feature Design
Open Questions
Would a Grid with these capabilities (i.e. named areas and autoflow + autogenerated rows/columns) simplify the way that you currently use Grid? For what scenario?
Which of the proposed enhancements would you find most useful?
The text was updated successfully, but these errors were encountered: