Hi guys,
I spend a whole evening figuring out how to get de selected item in the commandparameter inside the DataTemplate of the StartSwipeTemplate.
Somehow there is no way to get the actual item as SelectedItem. The only way is to handle the event and set the selecteditem of the SfListview manually. Is this behavior deliberate or did I miss something?
Setting the the commandparameter to "{Binding}" did also not work. It refers to the ViewModel of the page.
listview:SfListView.StartSwipeTemplate>
<DataTemplate x:Name="SwipeLeft">
<ImageButton
ToolTipProperties.Text="{m:GetString Edit}"
Command="{Binding Source={RelativeSource AncestorType={x:Type listview:SfListView}}, Path=BindingContext.Edit_Command}"
CommandParameter="{Binding Source={RelativeSource AncestorType={x:Type listview:SfListView}}, Path=SelectedItem}"
BackgroundColor="Green"
Source="edit.png"
WidthRequest="75"
HeightRequest="75"
Scale="0.75"
VerticalOptions="Center"/>
</DataTemplate>
</listview:SfListView.StartSwipeTemplate>
This is how I resolved it now:
private void SfListView_SwipeStarting(object sender, Syncfusion.Maui.ListView.SwipeStartingEventArgs e)
{
if (BindingContext is BudgetsViewModel viewModel && e.DataItem is Budget budget)
viewModel.SelectedItem = budget;
}
Frankly, I don't like these kind of hacks.