I am having trouble getting any binding to work for a SwipeItem
within a RadListView
(which is similar to a standard ListView
). In particular, I am trying to bind to the Command
property; however, I have attempted to bind to other properties, e.g., Text
, but to no avail.
<telerikDataControls:RadListView ItemsSource ="{Binding Users, Mode=OneWay}">
<telerikDataControls:RadListView.ItemTemplate>
<DataTemplate>
<SwipeControl>
<SwipeControl.RightItems>
<SwipeItems>
<SwipeItem Text="Delete"
Background="Red"
Foreground="White"
Command="{Binding DeleteCommand}">
<SwipeItem.IconSource>
<SymbolIconSource Symbol="Delete"/>
</SwipeItem.IconSource>
</SwipeItem>
</SwipeItems>
</SwipeControl.RightItems>
<Grid>
<TextBlock Text="{Binding Name"/>
</Grid>
</SwipeControl>
</DataTemplate>
</telerikDataControls:RadListView.ItemTemplate>
</telerikDataControls:RadListView>
Users
is set in the constructor of the ViewModel for the View; it is an ObservableCollection
of UserViewModel
, each of which has the properties I am trying to use (with PropertyChanged events).
The Name
binding works in the Grid
further down in the template and I have checked the DataContext
of the SwipeControl
and it is a UserViewModel
.
In my testing I have set up an Event
on the SwipeItem
:
<SwipeItem Text="Delete"
Background="Red"
Foreground="White"
Command="{Binding DeleteCommand}"
Invoked="SwipeItem_Invoked">
and handled it in the code-behind:
private void SwipeItem_Invoked(SwipeItem sender, SwipeItemInvokedEventArgs args)
{
UserViewModel userToDelete = (UserViewModel)args.SwipeControl.DataContext;
}
I can see in here that sender.Command
is null
.
Obviously, the quick solution is to use the Event pattern; however, I am trying to keep it MVVM and avoid code-behind as much as possible. I have never had issues binding to properties before so imagine I am just doing something fundamentally wrong.
Thanks.
Edit:
public class UserViewModel : MvxNotifyPropertyChanged // MvvmCross
{
public IMvxAsyncCommand DeleteCommand { get; }
private string _name;
public string Name // this property is bound in the Grid but will not bind in the SwipeItem
{
get => _name;
set => SetProperty(ref _name, value);
}
}