Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How to bind Button command to ViewModel and IsEnabled to model (bug?)?

$
0
0

I have a listview created with a data template for the group header and for the item. The listview has an ItemsSource "Weeks" in which there is an array with "items" which will be used to populate the items belonging to the group. Every item has a button which is binding to a value in the "item" model. But the button command is binding to the viewmodel. As soon as I do that, things go wrong. If I set "IsEnabled" to false when the listview is loading, it will not disable the button as soon as I have set the command in my viewmodel or model. If I don't assign the command everything works. If I remove the Command from the XAML, all is well.
The command will execute a check if a value is '0' and then will disable the button("IsEnabled=false"), this works all the time, no matter where the Command is binded/set. It is merely the loading. If the button is disabled after pressing the button, the button is scrolled out of view and then back in, the button is enabled again. So it is really connected to loading/showing the button.

I need to bind the Command to the viewmodel as I believe that is the way to do it and I need to know when the button is pressed so the viewmodel can handle some actions and UI updates.

<Button x:Name="minButton" Text="-" Style="{StaticResource borderlessButton}" IsEnabled="{Binding IsMinButtonEnabled}" Command="{Binding Source={x:Reference Name=PredictView}, Path=BindingContext.MinButton}" CommandParameter="{Binding .}" Grid.Column="1"/>

Is there something I'm doing wrong or is this a bug?


Viewing all articles
Browse latest Browse all 89864

Trending Articles