Search code examples
c#mvvmxamarin.formsdata-binding

How to bind property to another object inside BindableLayout.ItemsSource


I have BindableLayout, that binded to ViewModel property (which is actually a subclass), but inside this layout i'm trying to bind Command to VM another property. How can i specify property for binding in this case?

XAML code:

    <Grid BindableLayout.ItemsSource="{Binding ActualValues}"
          Grid.Column="0"
          Grid.ColumnSpan="2"
          Grid.Row="0">
        <BindableLayout.ItemTemplate>
            <DataTemplate>
                <Frame Margin="{Binding Margin}">
                    <Entry TabIndex="{Binding Id}"
                           Text="{Binding Value}"
                           Placeholder="{Binding Placeholder}"
                           Style="{StaticResource EntryStyle}">
                        <Entry.Behaviors>
                            <behaviors:EntryCompletedBehavior Command="{Binding EntryCompletedCommand}"/> 
                        </Entry.Behaviors>
                    </Entry>
                </Frame>
            </DataTemplate>
        </BindableLayout.ItemTemplate>
    </Grid>

Solution

  • You could set the binding path in xaml

    in xaml

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:xxx"
                 x:Class="xxx.MainPage"
    
                 x:Name="page"  // set name of ContentPage 
                 >
    
    Command="{Binding Source={x:Reference page} , Path=BindingContext.xxxCommand}" 
    

    xxxCommand is an ICommand which been defined in VM .