As I mentioned in my comment above, my command no longer works and was working fine with buttons manually built in XAML. Previously, I had an unbound FlexLayout containing buttons like this:
<Button x:Name="WalkButton" Text="Move" Grid.Row="3" Grid.Column="0" Command="{Binding DoAction}" CommandParameter="Walk"/>
<Button x:Name="RunButton" Text="Talk" Grid.Row="3" Grid.Column="1" Command="{Binding DoAction}" CommandParameter="Run"/>
etc...
Now I bind to "Moves", an ObservableCollection<string>
:
<FlexLayout BindableLayout.ItemsSource="{Binding Moves}" Wrap="Wrap" VerticalOptions="CenterAndExpand" HorizontalOptions="FillAndExpand">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Button x:Name="{Binding}" Text="{Binding}" Command="{Binding DoAction}" CommandParameter="{Binding}"/>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
The buttons look great (thanks!)...but...they do nothing when pressed. Upon stopping the application, the Console reports:
[0:] Binding: 'DoAction' property not found on 'walk', target property: 'Xamarin.Forms.Button.Command'
[0:] Binding: 'DoAction' property not found on 'walk', target property: 'Xamarin.Forms.Button.Command'
[0:] Binding: 'DoAction' property not found on 'run', target property: 'Xamarin.Forms.Button.Command'
[0:] Binding: 'DoAction' property not found on 'run', target property: 'Xamarin.Forms.Button.Command'
[0:] Binding: 'DoAction' property not found on 'climb', target property: 'Xamarin.Forms.Button.Command'
[0:] Binding: 'DoAction' property not found on 'climb', target property: 'Xamarin.Forms.Button.Command'
I expected this to work without modifying DoAction
in my ViewModel because CommandParameter="{Binding}"
should send "walk", "run", etc as an argument just like before. Weird that each Binding error is reported twice, right? Also, my can execute code stopped working:
void RefreshCanExecutes()
{
(DoAction as Command).ChangeCanExecute();
}
I really do like the BindableLayout.ItemsSource
approach so I want to modify my code accordingly. But, I don't understand how adding a binding to the FlexLayout
could have caused the C# code to stop working. (and if that really can't be the reason...well I have some real digging to do!)