Binding: 'TestCommand' property not found on 'ProductClas', target property: 'Xamarin.Forms.Button.

BuhhSathBuhhSath USMember ✭✭

Hello,
Binding my ListView is working fine with my (MyBindableCollection), however, the button binding I'm getting error (Binding: 'TestCommand' property not found on 'ProductClas', target property: 'Xamarin.Forms.Button.). Looks like it's looking a property in my class ProductClas instead a ICommand in my class MyViewModel.

Why?

        <ListView ItemsSource="{Binding MyBindableCollection}" SeparatorColor="Gray" HasUnevenRows="True">
             <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <ViewCell.View>
                        <Label  Text="{Binding Price" />
                                        <Button
                                            Command="{Binding TestCommand}"
                                            BackgroundColor="#ddd" 
                                            Grid.Row="3" Grid.Column="1" Grid.RowSpan="2" 
                                            Text="ADD" TextColor="Green" 
                                            BorderRadius="0">
                                        </Button>
        .....
        .....                                    
        </ListView>

//MyViewModel
public ObservableCollection MyBindableCollection { get; set; }

Best Answer

Answers

  • PaulDistonPaulDiston USUniversity ✭✭✭✭

    Hi,

    Is your MyViewModel class added as an item to the MyBindableCollection? If so, would you provide the code for that class as well?

    Thanks

    Paul Diston

  • BuhhSathBuhhSath USMember ✭✭

    It's not added, maybe I'm missing this, can you provide a piece of code how do that?

  • PaulDistonPaulDiston USUniversity ✭✭✭✭

    Hi,

    I am not sure what you want your ViewModel to look like. I recommend reviewing the following, which includes how to data bind :-

    developer.xamarin.com/guides/cross-platform/xamarin-forms/Xaml-for-Xamarin-forms/data_binding_basics/

    Hope this helps.

    Paul Diston

  • BuhhSathBuhhSath USMember ✭✭

    I just want to my Button fires 'TestCommand' (Command="{Binding TestCommand}")

  • BuhhSathBuhhSath USMember ✭✭
    edited April 2015

    @PaulDiston I don't know if it's the best solution, but I had to Implement ICommand on ProductClas, initialize MyViewModel, then was possible to call TestCommand (Inside ProductClas).

    Unfortunately changes in My BindableCollection not fires MyView :neutral:

  • BuhhSathBuhhSath USMember ✭✭
    edited April 2015

    Please ignore my last post. I solved defining (SingleInstance) Ioc autofac.

  • DorababuDorababu USMember ✭✭

    Hi @BuhhSath , I am having the same problem, can you please tell how did you solved that.

  • BuhhSathBuhhSath USMember ✭✭
    edited November 2015

    @Dorababu I'm using this component: https://github.com/corradocavalli/Corcav.Behaviors
    Nuget: https://github.com/corradocavalli/Corcav.Behaviors

    <Button Text="{Binding NickName}"> <b:Interaction.Behaviors> <b:BehaviorCollection> <b:EventToCommand CommandNameContext="{b:RelativeContext MainPage}" EventName="Clicked" CommandName="NickSelectedCommand" CommandParameter="{Binding NickName}" /> </b:BehaviorCollection> </b:Interaction.Behaviors> </Button>

  • DorababuDorababu USMember ✭✭
    edited November 2015

    Thanks for the reply @BuhhSath . Its worked without using Behaviors also.

Sign In or Register to comment.