-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Windows] Update CollectionView changing ItemsLayout #14532
Conversation
|
||
UpdateItemTemplate(); |
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.
why is this removed? were is It being called now?
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.
With the PR changes nowhere, check this comment and let me know if you have any questions.
@@ -32,6 +32,10 @@ public abstract partial class ItemsViewHandler<TItemsView> : ViewHandler<TItemsV | |||
bool _emptyViewDisplayed; | |||
double _previousHorizontalOffset; | |||
double _previousVerticalOffset; | |||
double _previousItemSpacing; |
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.
Why do we need these?
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.
To avoid to recreate and inject the ItemContainerStyle if the spacing not changed. For example, resizing the Window. In this case, without checking the changes will change the ItemContainerStyle once every time the size changes.
@@ -279,18 +283,40 @@ protected virtual void UpdateEmptyView() | |||
|
|||
protected virtual void UpdateItemsLayout() | |||
{ | |||
ListViewBase.IsSynchronizedWithCurrentItem = false; | |||
if (ListViewBase is FormsGridView gridView) |
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.
Here can find the main change.
In Xamarin.Forms, what happens is that, based on the ItemsLayout, a native ListView or GridView is used on Windows. This forces to dynamically change the native control on runtime needing to map everything and inject items etc.
In .NET MAUI, the code is very similar but the logic to change controls on the fly is missing. For that reason, it didn't work. I have carried out a test, where I basically changed the platformview, removing and adding it to the parent. While it is possible, I wonder, is it necessary? Resizing the Window performs this very expensive task. Isn't it enough to always use a GridView and change the Layout properties? This is what is proposed with the changes in this PR.
src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs
Outdated
Show resolved
Hide resolved
src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs
Outdated
Show resolved
Hide resolved
src/Controls/src/Core/Platform/Windows/Extensions/CollectionViewExtensions.cs
Outdated
Show resolved
Hide resolved
src/Controls/src/Core/Platform/Windows/Extensions/CollectionViewExtensions.cs
Show resolved
Hide resolved
FYI: this PR broke #14391 and breaks the |
Can this fix be merged into an update for 7.x? It's a blocking issue for my app. |
@samhouts |
Description of Change
Update CollectionView changing ItemsLayout on Windows.
To test the changes, launch the .NET MAUI Gallery on Windows and navigate to the CollectionView samples. Select the added "Adaptive CollectionView" sample. This sample change the CollectionView ItemsLayout property based on the Page Width. Resize the Window to validate that the CollectionView updates the layout.
Issues Fixed
Fixes (but reverted) #7747