Enable Grid to dynamically switch layouts #541
Replies: 5 comments 14 replies
-
PR made here #4474 |
Beta Was this translation helpful? Give feedback.
-
Hi @nandin-borjigin, appreciate your enthusiasm for this topic. It'd be good to map out some different scenarios we'd like to address and possible alternatives for how we can accomplish these goals. Is extending Grid the best option or is this a new type of panel for instance? Have you see this proposal in the WinUI repo? It covers some similar ideas as well, so it'd be interesting to compare and contrast those suggestions from the platform team with what you're trying to do here as well. Mind if we talk about this a bit more and figure out how we can ensure we create a general solid solution to the issues you're trying to solve? |
Beta Was this translation helpful? Give feedback.
-
I'd like to strongly dispute this claimed pro for AreaDefinitions:
It's an entirely new approach and something not seen anywhere else in XAML, so claiming it's easy to understand without any broad level of feedback is optimistic at best. Imagine seeing this for the first time in a codebase that you inherit from someone else. My first thought is WTF. Even after thinking on this problem for a few days, I still see the example and think it looks weird and wrong and out of place inside a XAML file. I look at it and wonder about what it might mean and how it might be interpreted and don't have certainty. Regarding the GridLayoutDefinition option, I'd like to see more examples of how it works with Visual State definitions so there is a complete example of what would be used in an implemented version. <Grid x:Name="RootGrid" RowDefinitions="Auto" ColumnDefinitions="Auto,Auto,*">
<ui:GridExtensions.Layouts>
<ui:GridLayoutDefinition x:Key="Narrow" Rows="Auto,Auto" Columns="Auto,*">
- <ui:GridLayoutData Target="{x:Bind Number}" Row="0" Column="0"/>
- <ui:GridLayoutData Target="{x:Bind Title}" Row="0" Column="1"/>
<ui:GridLayoutData Target="{x:Bind Description}" Row="1" ColumnSpan="2"/>
</ui:GridLayoutDefinition>
</ui:GridExtensions.Layouts>
<TextBlock x:Name="Number" Grid.Column="0">1</TextBlock>
<TextBlock x:Name="Title" Grid.Column="1">Lorem Ipsum</TextBlock>
<TextBlock x:Name="Description" Grid.Column="2">Lorem ipsum dolor sit amet...</TextBlock>
</Grid> They're not necessary as they set the same values for The consequence here is that it would make implementation more complicated when switching between different layouts as everything would need to be reset back to the default position within the grid if an element was changed in one layout but another layout didn't have a specific override for that element. |
Beta Was this translation helpful? Give feedback.
-
I think the scenario described above is totally valid. However I don't think (mis)using Grid to solve that scenario is the right avenue. IMHO it looks more to me like what you really need is a wide and narrow template to switch between. For instance the TwoPaneView control does exactly this for you. |
Beta Was this translation helpful? Give feedback.
-
We're discussing a new control that was designed independently by different community members and may serve some of the use cases covered by this idea -> #540 |
Beta Was this translation helpful? Give feedback.
-
Usecase
Imagine we want to show a list of items and each list item is a 3-column grid.
Now, we want to be responsive to the window size changes and decide to collapse this list item into 2 rows when the window width is narrow.
Potential approach
Problem
It's not really intuitive to declare a 2 x 3 grid layout when what we really need is either 1 x 3 or 2 x 2, depending on the window width. In above approach, we're imperatively dictating how the narrow layout would be instead of declaratively describing it and let the library handles the dirty work.
Further, another problem here is the visual state setter would quickly become maintenance hell when the layout becomes slightly complex. Just imagine what if we want to add column spacing to the grid.
This is what we would get if we simply add
ColumnSpacing="10"
on theGrid
element. The gutter between 2nd and 3rd column is still there since the 3rd column is effectively there even if it's of 0 width, so the spacing exists. To better workaround this, we need to modify the visual state setters. We need to make theTitle
element span 2nd and 3rd columns and make theDescription
element span 3 columns. And this is only for a minor change like adding a column spacing.Proposal
Provide
Grid
with a set of attached properties to enable programmers to declaratively describe the possible layouts and easily switch between them.Beta Was this translation helpful? Give feedback.
All reactions