BindableLayout does not work with ObservableCollection?

NielsCupNielsCup NLMember ✭✭✭

I am trying to bind a StackLayout according to this documentation but I find that when my collection changes, the changes are not visible in my bound StackLayout. If I replace the StackLayout with a ListView everything works fine. Is this a known limitation/issue in BindableLayouts?

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Can you post your C# for the ViewModel and the XAML for the layout?
    Without actually seeing your code there isn't much to evaluate.

  • LeloLelo Member ✭✭✭

    @NielsCup said:
    I am trying to bind a StackLayout according to this documentation but I find that when my collection changes, the changes are not visible in my bound StackLayout. If I replace the StackLayout with a ListView everything works fine. Is this a known limitation/issue in BindableLayouts?

    It should be working

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @Lelo
    I do binding in StackLyouts so I know it works.
    But without your XAML there is little to help with.

    Here's an example from a live project so I know it works. FlexLayout, StackLayout makes no difference here.
    Worst case - test your binding with this FlexLayout and if that works swap in a StackLayout

        <ScrollView>
            <FlexLayout
                Padding="0"
                AlignContent="Center"
                AlignItems="Center"
                BindableLayout.ItemsSource="{Binding MyCoolCollection}"
                Direction="Row"
                JustifyContent="Center"
                Wrap="Wrap">
                <BindableLayout.ItemTemplate>
                    <DataTemplate>
                        <Grid
                            HeightRequest="{StaticResource ButtonHeight}"
                            WidthRequest="{StaticResource ButtonWidth}"
                            Margin="5"
                            Padding="0"
                            BackgroundColor="{StaticResource BlueTextColor}"
                            IsVisible="{Binding IsEnabled}">
                            <Grid.GestureRecognizers>
                                <TapGestureRecognizer
                                    Command="{Binding Source={x:Reference this}, Path=MyViewModel.DoThisCommand}"
                                    CommandParameter="{Binding .}"
                                    NumberOfTapsRequired="1"
                                    Tapped="ButtonAnimationMethod" />
                                <TapGestureRecognizer
                                    Command="{Binding Source={x:Reference this}, Path=MyViewModel.DoOtherThingCommand}"
                                    CommandParameter="{Binding .}"
                                    NumberOfTapsRequired="2"
                                    Tapped="ButtonDoubleTapAnimationMethod" />
                            </Grid.GestureRecognizers>
    
                            <Label
                                HorizontalOptions="CenterAndExpand"
                                VerticalOptions="CenterAndExpand"
                                BackgroundColor="Transparent"
                                FontAttributes="Bold"
                                HorizontalTextAlignment="Center"
                                Text="{Binding FriendlyName, Mode=OneWay}"
                                TextColor="{StaticResource TagForegroundColor}"
                                VerticalTextAlignment="Center"
                                Style="{StaticResource LabelStyleMed}" />
                        </Grid>
    
                    </DataTemplate>
                </BindableLayout.ItemTemplate>
            </FlexLayout>
        </ScrollView>
    
  • NMackayNMackay GBInsider, University mod

    Works fine with grids and stacklayouts in Forms 3.6, haven't test 4.0

Sign In or Register to comment.