Replies: 4 comments 12 replies
-
Need some more input here on customizing the breakpoint values for window size fyi @francoistanguay / @Xiaoy312 / @agneszitte |
Beta Was this translation helpful? Give feedback.
-
im not fond of the multi-DataTemplate approach with ResponsivePresenter, since you'd have to duplicate the xaml (when there are overlaps) so it doesnt work well say for reducing verbosity. it also creates a barrier between stuffs inside and outside of that presenter, eg: you cant access x:name across the border; you cant directly define event handler from the inside without some tricks (the same issue we had to deal with SamplePageLayout, that we solved like this: https://github.com/unoplatform/uno.toolkit.ui/blob/4.0.0/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Controls/DrawerControlSamplePage.xaml.cs#L49) however, it is good for when we have two completely different views based on narrow/wide |
Beta Was this translation helpful? Give feedback.
-
So we should have a central spot where a ResponsiveLayout {Narrow = 300, Wide = 800, etc. } object will be defined in the app resources as a StaticResource that both the ResponsiveView and Responsive[Value] will reference using App.Resources and use as the source of truth for the breakpoint values. On top of that, a performance concern that we should address is subscribing to Window.SizeChanged for each individual binding using the markup extension as that can add a lot of event handlers. So we should come up with some sort of manager that will maintain a list, per window instance, of all instances that need to listen to SizeChanged. And so that manager class will hook to each registered window instance's SizeChanged and then iterate the list of the window instance's registrants and notify them of the new size |
Beta Was this translation helpful? Give feedback.
-
closing this discussion as the discussed features have been implemented: |
Beta Was this translation helpful? Give feedback.
-
The Problem
There is currently no clean and concise way to handle responsive layouting with XAML. The main way of accomplishing this is through Visual States and AdaptiveTriggers.
For example, changing simple properties on a control based on window width would look something like this:
Achieving something more complex like changing the structure of a large part of the UI based on window width would be even more complex and verbose.
Scenarios
There are multiple different scenarios where different responsive design techniques can be used to achieve what we want. We can explore a few and brainstorm on different solutions to make it easy to adapt your XAML to these situations.
Replace/Re-architect
Here we have large pieces of the UI that need to change based on windows size. This technique lets you switch the user interface for a specific breakpoints. In this example, the nav pane and its compact, transient UI works well for a smaller screen, but on a larger screen, tabs might be a better choice.
Currently, this type of scenario would be achieved using multiple named containers defined in the UI driven by Visibility that is set to Visible/Collapsed based on certain Visual States.
Proposed Solution
A reusable component could be created that allows for multiple layouts based on the current display size. For argument sake, let's call it something like
ResponsivePresenter
.Properties
Usage
We can clean up the XAML even more by extracting the wide layout into a StaticResource and defaulting the content of the
ResponsivePresenter
to theDefaultTemplate
:Reposition
You can alter the location and position of UI elements to make the most of the window size. In this example, the smaller window stacks elements vertically. When the app translates to a larger window, elements can take advantage of the wider window width.
In case like this, we don't necessarily need a completely new layout or UI structure, this can be done by driving just a few properties of your layout to adapt to the window size.
Using the
ResponsivePresenter
is an option here but can be a bit overkill, it would be good to have some sort of lightweight way of achieving this.Proposed Solution
We can dynamically set any property using a custom Markup Extension.
We can have something called
ResponsiveValue
as a custom markup extension that has the following parameters:So, we could theoretically do something like:
This is a very simplified version of what can be done, I know that the image above shows the A section as larger than the B section.
Other design techniques
Beta Was this translation helpful? Give feedback.
All reactions