Home > Back-end >  How to Binding StackLayout data in code behind Xamarin
How to Binding StackLayout data in code behind Xamarin

Time:09-17

I have

  1. Page.xml

    <ListView x:Name="myCart" HasUnevenRows="true">
       <ListView.ItemTemplate>
         <DataTemplate>
           <ViewCell>
              <Grid Padding="0" Margin="0">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                  <RowDefinition Height="auto" />
                </Grid.RowDefinitions>
                <Grid Grid.Row="0" Grid.Column="0">
                  <Label TextColor="#333" Text="111" />
                </Grid>
              </Grid>
           </ViewCell>
         </DataTemplate>
       </ListView.ItemTemplate>
    </ListView>
    
    <StackLayout x:Name="stdata">
      <BindableLayout.ItemTemplate>
        <DataTemplate>
           <Label TextColor="#333" Text="111" />
        </DataTemplate>
      </BindableLayout.ItemTemplate>
    </StackLayout>
    
  2. Page.xml.cs

    ....
    var mycartss = Preferences.Get("CartUser", "defaultcart");
    var getcartss = JsonConvert.DeserializeObject<List<CartUser>>(mycartss);
    cartUsers = getcartss;
    // myCart.ItemsSource = cartUsers; -->If I use ListView I can Binding data like this
    stdata.BindableLayout.ItemsSource.....????
    

Problem 1: I have set the property HasUnevenRows="true" but it still doesn't work

enter image description here

Problem 2: If I use StackLayout then how do I bind data in code behind? stdata.BindableLayout.ItemsSource.....????

I have consulted some articles on stackoverflow.com but it is quite cumbersome for me. Hope for help. Thank you

CodePudding user response:

this is covered in the docs

BindableLayout.SetItemsSource(stdata, cartUsers);
  • Related