ContentView bindable Command

FotalFotal Member ✭✭✭
edited March 2018 in Xamarin.Forms

Hi !

In my ContentView, there is a ListView that is assigned the ItemTapped command using the EventToCommandBehavior:

<ListView x:Name="ItemsView"                  
                    ItemTemplate="{StaticResource DataTemplate.JobObject}"
                    ItemsSource="{Binding DayInfo.Items}"
                    RowHeight="{Binding ItemHeight}"
                    HeightRequest="{Binding ColumnHeight}">

                    <ListView.Behaviors>
                        <behaviors:EventToCommandBehavior EventName="ItemSelected"
                                                          Command="{Binding ItemTappedCommand}"                                                       
                                                          EventArgsConverter="{StaticResource SelectedItemConverter}"/>
                    </ListView.Behaviors>
                </ListView>

Then I created a BindableProperty in ContentView that links my command:

public static readonly BindableProperty ItemTappedCommandProperty = BindableProperty.Create(
            "ItemTappedCommand",
            typeof(ICommand),
            typeof(ColumnView));

public ICommand ItemTappedCommand
        {
            get => (ICommand) GetValue(ItemTappedCommandProperty);
            set => SetValue(ItemTappedCommandProperty, value);
        }

But when I try to link a property from ContentPage then my CommandProperty always is null. I tried to process the command in this ContentView and everything works fine, but the binding does not work.

Best Answer

  • FotalFotal ✭✭✭
    edited March 2018 Accepted Answer

    F*ck, inattentively, my mistake is: ItemTappedCommand = "ItemTapped" in Xaml code
    that's the right solution: ItemTappedCommand = "{Binding ItemTapped}"

Answers

Sign In or Register to comment.