i am currently working on a simple app developped with Xamarin and MvvmCross. I have a simple list of items and i want a click on an item open a new view.
I managed to do that in Android with :
this code in the .axml of the view
ListCustomersView.xaml
<MvxListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxItemTemplate="@layout/listcustomerscell"
local:MvxBind="ItemsSource ListCustomers; ItemClick ShowCommand"
android:id="@+id/listCustomersView" />
and this code in the ViewModel file :
ListCustomersViewModel.cs
private MvxCommand<CustomerListDTO> _showCommand;
public ICommand ShowCommand
{
get { return _showCommand ?? (_showCommand = new MvxCommand<CustomerListDTO>(c => this.ShowCustomerDetail(c))); }
}
public void ShowCustomerDetail(CustomerListDTO c)
{
ShowViewModel<CustomerDetailViewModel>(new CustomerDetailParameters() { CustomerID = c.Id });
}
As you can see, i send a parameter through the command : an instance of the CustomerDetailParameters class. It works well in Android, but i do not manage to do that in Windows Phone.
I m using this code in the ListCustomersView.xaml :
<ListBox Name="listBox" ItemsSource="{Binding ListCustomers}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<controls:ListCustomersCell />
</DataTemplate>
</ListBox.ItemTemplate>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding ShowCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
The ShowCommand is well called but the CustomerListDTO which should be sent is null. I imagine i am not using the good code. If you have any idea, i will take them.
Thanks for any help and have a good day !
Command paramter is not passed to the command. Try below code by passing CommandParameter to the VM