Your view code behind:
ListxNameHere.Behaviors.Add(new EventWithArgsToCommand
{
EventName = nameof(List.ItemTapped),
Command = vm?.SelectYourListItem,
Converter = new ItemTapEventArgsToSelectedItemConverter()
);
Your view model:
private RelayCommand<YourModel> _selectYourListItem;
public RelayCommand<YourModel> SelectYourListItem => _selectYourListItem ?? (_selectYourListItem = new RelayCommand<YourModel>(async yourModel => await InvokeSelectYourListItem(yourModel)));
Event to args converter:
public class ItemTapEventArgsToSelectedItemConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var eventArgs = value as ItemTapEventArgs;
return eventArgs?.Item;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
0
Lance | Manager Technical Support
Telerik team
answered on 18 Sep 2017, 09:34 PM
Hi Haluu,
If you can't have any code-behind or just want all XAML, you can use an EventToCommandBehavior. Here's a good example.
You'd still use Namyslaw's converter for the args, or you can just pass the whole args and manage it in the command..
Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items