Home > Enterprise >  Xamarin Form Add Multiple Binding
Xamarin Form Add Multiple Binding

Time:01-30

Please I need help.

I have my Xamarin Form app that works very well with DataBinding to its View Model named OrderDetailViewModel.

But today I have to add another DataBinding field in line 10 Binding OrderStatusMessage that is bind to its Xaml.cs file (code behind) but out of curiosity this field doesn't work I mean it is not changing the Label Text dynamically after binding the label text to a property located in its xaml.cs file (code behind file).

In line 4 you can find the data binding to MVVM file called OrderDetailViewModel which works well.

But the issue is in line 10 Binding OrderStatusMessage which is a DataBinding to its own xaml.cs file doesn't change the Label text to new message. I tested the same code Binding OrderStatusMessage outside of the CollectionView.ItemTemplate tag and it's working properly, so only when I put inside CollectionView.ItemTemplate tag that's is not pulling the updated text.

In the below code there's only one property that is bind to its xaml.cs file (code behind) which is in line 10 {Binding OrderStatusMessage} that doesn't get the updated text, the rest are bind to the MVVM which works well.

PS : I would like to add Multiple Binding to this below code in line 4 :

filename : OrderDetailViewPage.xaml

<CollectionView.ItemTemplate >
                            <DataTemplate >
                                <StackLayout
                                    xct:TouchEffect.LongPressCommand="{Binding LongPressCommand, Source={RelativeSource AncestorType={x:Type local:OrderDetailViewModel}}}"
                                    xct:TouchEffect.LongPressCommandParameter="{Binding .}"
                                    xct:TouchEffect.PressedScale="1.2"
                                    xct:TouchEffect.NativeAnimation="True">

                                    <StackLayout>
                                        <Label Text="{Binding OrderStatusMessage}" HorizontalOptions="CenterAndExpand" FontFamily="fasolid" FontSize="18" FontAttributes="Bold" TextColor="Black"/>
                                    </StackLayout>

                                    <Label Text="{Binding Id}"
                                        FontSize="Medium"/>
                                    <Label Text="Order number" HorizontalOptions="CenterAndExpand"/>
                                    <Label Text="{Binding OrderId}"
                                        TextColor="Purple" FontAttributes="Bold"
                                        FontSize="Large" HorizontalOptions="CenterAndExpand"/>
                                    <Label Text="{Binding OrderDetail}"
                                        TextColor="Purple"
                                        FontSize="Small" />
                                    <Label Text="{Binding OrderDate}"
                                        TextColor="Purple"
                                        FontSize="Small" />
                                    <Label Text="{Binding IsOrderComplete}"
                                        TextColor="Purple"
                                        FontSize="Small" />
                                </StackLayout>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>

CodePudding user response:

Have you tried bind your Label inside CollectionView.ItemTemplate using Path property? Like this : <Label Text = "{Binding Path=OrderStatusMessage, Source = {x:Reference pageName}}"/>

  • Related