maui icon indicating copy to clipboard operation
maui copied to clipboard

CollectionView.ItemsLayout binding does not work

Open sjorsmiltenburg opened this issue 2 years ago • 10 comments

Description

When I define ItemsLayout="VerticalGrid,4" in xaml, I see 4 columns. But when I bind the ItemsLayout property to a viewmodel and update the property, the grid refreshes, but does not show more than one column. The same code works as expected on android.

I added a sample solution that shows the behaviour

Steps to Reproduce

run the supplied code on windows -> it does not show extra columns on presssing "add column" run the supplied code on android -> it does work as expected

Link to public reproduction project repository

https://github.com/sjorsmiltenburg/Maui.CollectionView.ItemsLayoutBug

Version with bug

7.0.86

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows

Did you find any workaround?

no workaround as of yet. I tried to run the collectionviewdemoes to see if I could find a working sample where I could learn from, but I am kind of shocked how many of these samples crash / don't work (on windows). It's not a good way to make a first maui impression. https://github.com/dotnet/maui-samples/tree/main/7.0/UserInterface/Views/CollectionViewDemos

Relevant log output

No response

sjorsmiltenburg avatar Jun 03 '23 21:06 sjorsmiltenburg

Tested on main branch and cannot reproduce the issue: issue-15434

The issue have been fixed by https://github.com/dotnet/maui/pull/14532

jsuarezruiz avatar Jun 05 '23 08:06 jsuarezruiz

Hi, thank you for the quick verification. I am on stable branch of visual studio v17.6.2 What version will this fix be released in? Do I need to switch to the preview channel to see it? image

sjorsmiltenburg avatar Jun 05 '23 10:06 sjorsmiltenburg

Is available on the latest .NET 8 Preview. Suggested to backport it to .NET 7 but is not yet available there.

jsuarezruiz avatar Jun 05 '23 14:06 jsuarezruiz

@sjorsmiltenburg, thank you for reporting this. I have spent the past couple of hours trying to figure out why ItemsLayout="VerticalGrid, 2" works but ItemsLayout="{Binding ItemsLayoutCols}" results in a single column. BTW, is Binding supposed to be a string like "VerticalGrid, 2"?

cdavidyoung avatar Jul 15 '23 23:07 cdavidyoung

@cdavidyoung look at the sample I provided in this bug report: https://github.com/sjorsmiltenburg/Maui.CollectionView.ItemsLayoutBug/blob/main/MainPage.xaml.cs you do not bind to a string but to a property of type ItemsLayout

sjorsmiltenburg avatar Jul 16 '23 15:07 sjorsmiltenburg

@sjorsmiltenburg, that works! Thanks. I tested it both on Windows and Android.

cdavidyoung avatar Jul 17 '23 20:07 cdavidyoung

Verified this issue with Visual Studio Enterprise 17.9.0 Preview 2. Can repro on windows platform with sample project. (.NET7&.NET8) https://github.com/sjorsmiltenburg/Maui.CollectionView.ItemsLayoutBug

Zhanglirong-Winnie avatar Jan 12 '24 07:01 Zhanglirong-Winnie

This problem was fixed by this pullrequest that was merged, but it broke other things, so it was reverted last minute. I'm a bit worried that this issue having the status 'merged' does not alert the team that this issue is still open. At least there has not been any action on it since the revert. Windows is a very important platform for me, so this is a showstopper for my app that needs to update it's amount of columns on a resize with some custom logic. I've already done my migration to MAUI and invested time in continuing my development there assuming I could launch it soon. But I can't deploy this version and now I'm needing to go back to XF for an update for my app. Double / triple work. This sucks.

sjorsmiltenburg avatar Jan 12 '24 08:01 sjorsmiltenburg

Will this finally be fixed in the next Service Release? :/

DDHSchmidt avatar Mar 05 '24 17:03 DDHSchmidt

Still is not fixed. I can confirm when binding ItemsLayout to Width using this ItemsLayout="{Binding Width, Source={x:RelativeSource AncestorType={x:Type Grid}}, Converter={StaticResource WidthToItemsLayoutConverter}}" and simple converter:

public class WidthToItemsLayoutConverter : IValueConverter
{
    public object Convert(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
    {
        if (value == null)
            return LinearItemsLayout.Vertical;
        double x  = System.Convert.ToDouble(value);
        return new GridItemsLayout(x < 0 ? 3 : x < 400 ? 1 : 2, ItemsLayoutOrientation.Vertical);
    }

    public object ConvertBack(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }

}

First call of converter when value is -1 returns 3 column and it will not be changed when Width changed

tkouba avatar Apr 15 '24 21:04 tkouba

Still is not fixed. I can confirm when binding ItemsLayout to Width using this ItemsLayout="{Binding Width, Source={x:RelativeSource AncestorType={x:Type Grid}}, Converter={StaticResource WidthToItemsLayoutConverter}}" and simple converter:

public class WidthToItemsLayoutConverter : IValueConverter
{
    public object Convert(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
    {
        if (value == null)
            return LinearItemsLayout.Vertical;
        double x  = System.Convert.ToDouble(value);
        return new GridItemsLayout(x < 0 ? 3 : x < 400 ? 1 : 2, ItemsLayoutOrientation.Vertical);
    }

    public object ConvertBack(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }

}

First call of converter when value is -1 returns 3 column and it will not be changed when Width changed

Could you attach a small sample where reproduce the issue?. Thanks.

jsuarezruiz avatar Jun 06 '24 14:06 jsuarezruiz

I have a reproducable sample in the repo mentioned below. It is behind the "bug 6 button" of the application. It has been updated to the latest preview builds of .net 9 and maui. It will start with 3 columns and should be able to switch to 4 and 6 columns, but it does not update https://github.com/sjorsmiltenburg/maui_bugs

sjorsmiltenburg avatar Jun 11 '24 13:06 sjorsmiltenburg