Forum Xamarin Xamarin.Forms

CollectionView bug in Right To Left Mode

hamidDdhamidDd USMember ✭✭

Hello.
I tried the Collectionview and it seems it has a bug when flowDirection is RightToLeft and ItemsLayout set to GridItemsLayout with Orientation Vertical.(at least Span =2)
In this case the Collectionview itself appears right to left , but the items sequence is not like what in items-source and items are actually laid from Left to Right.(example :with Span =3,first item in the View is Third one in bound itemsSource)
I hope someone can help to solve the problem ,because I’m using Xamarin Forms and I need this feature.
Thank You.

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    The flowDirection won't change the order of the items in CollectionView.
    If you want to change the order of items from the end to start you can reverse the items source like:

    private void Button_Clicked(object sender, EventArgs e)
    {
        var itemsSource = myCollectionView.ItemsSource as List<ItemModel>;
        itemsSource.Reverse();
    
        myCollectionView.ItemsSource = null;
        myCollectionView.ItemsSource = itemsSource;
    }
    

    Get the effect like:

  • hamidDdhamidDd USMember ✭✭

    Hello,
    Thanks for your very kind answer.But my Problem is not reversing the list items order.
    Let say the items indexes in bound Collectionview are from 1 to 10 and Collectionview properties is defined as follows:
    1-FlowDirection="RightToLeft"
    2-<CollectionView.ItemsLayout>
    <GridItemsLayout Span="2" Orientation="Vertical"/>
    </CollectionView.ItemsLayout>
    With mentioned setup, them CollectionView itself visually appears Right To Left , but it's items arrangement is from left to right : I mean the most Right item in the first row of CollectionView is Second item in the List(Following Image) and this behavior is repeated on all rows:

    However the right order of items in **Right to Left **flow direction must be like the following picture:

    Thank You.

  • LandLuLandLu Member, Xamarin Team Xamurai

    The collection view's FlowDirection won't change the order of the items as I said above.
    It seems you are raising a feature request of Collection View if you don't want to start from the items source.
    I've seen you posted an issue on GitHub:
    https://github.com/xamarin/Xamarin.Forms/issues/8260
    We'll keep tracking the progress.

  • hamidDdhamidDd USMember ✭✭

    Hello and once again thanks for your rapid and kind answer.
    But I guess this is a BUG in CollectionView .
    I don't want the FlowDirection property changes the order of items , I want the items appear in the view as they are in bound List(ItemsSource) according to FlowDirection .
    In Right To Left Mode , This CollectionView just Shifts the bound items to the Right but the items themselves are arranged from left to right.(please compare 2 following images depict this difference in WPF and XAMARIN for Right To Left Mode)
    I think the natural behavior when FlowDirection=RightToLeft ** is as follow:
    1-first item in the bound list goes to most right column (item index 1)
    2-the next item (item index 2) must seat inside the next column(the column which is at the Left of First Column and so on)
    please look at the following image in WPF for **FlowDirection=RightToLeft **(please concern item Indexes and their arrangement)

    Now compare it with Xamarin Forms when FlowDirection=RightToLeft (please concern item Indexes and their arrangement)

    What I mean is that the items must appear according to the FlowDirection: **for Right To Left ,the first item must be the most right one in the CollectionView and rest of the items must be laid out in direction defined by FlowDirection
    .
    Thank You.

Sign In or Register to comment.