Net Maui CollectionView How to do bindable property for orientation ?

Sami 856 Reputation points
2023-06-08T20:19:55.3766667+00:00
custom collectionview is not working like that what is wrong with them ?

<custom:TabsCollectionView Grid.Row="1"  ItemSource="{Binding CartMenu}" AOrientation="Vertical" ASpan='3'/>

               <CollectionView.ItemsLayout>
                    <GridItemsLayout Orientation="{Binding Source={x:Reference AView}, Path=AOrientation, Mode=OneWay}" Span="{Binding Source={x:Reference AView}, Path=ASpan, Mode=OneWay}" />
                </CollectionView.ItemsLayout>



    public static readonly BindableProperty AOrientationProperty = BindableProperty.Create(   nameof(AOrientation),   
typeof(ItemsLayoutOrientation),   
typeof(ACollectionView),   
null,      
BindingMode.OneWay);      

public ItemsLayoutOrientation AOrientation     
{         
          get => (ItemsLayoutOrientation)GetValue(AOrientationProperty);        
          set => SetValue(TabOrientationProperty, value);     
}       

public static readonly BindableProperty ASpanProperty = BindableProperty.Create(   
nameof(ASpan),  
typeof(double),   
typeof(ACollectionView),   
null,      
BindingMode.OneWay);      

public double ASpan     
{         
           get => (double)GetValue(ASpanProperty);         
           set => SetValue(ASpanProperty, value);    
 }
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,859 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 35,291 Reputation points Microsoft Vendor
    2023-06-09T05:32:33.5233333+00:00

    Hello,

    With the code you provided, I noticed that you are trying to do data binding for orientation. Orientation="{Binding Source={x:Reference AView}, Path=AOrientation, Mode=OneWay}" Span="{Binding Source={x:Reference AView}, Path=ASpan, Mode=OneWay}".

    This is because Orientation is not a bindable property, and you could refer to the solution proposed by the maui developers Can not bind Orientation in LinearItemsLayout #4628.

    This is as-designed. The Orientation of the ItemsLayout is not a BindableProperty. If you want to use a binding to set/update the orientation of a CollectionView at runtime, you have to bind the entire ItemsLayout. Something like: <CollectionView ItemsLayout="{Binding ItemsLayout}"> And set ItemsLayout in your view model to whatever layout you want.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful