I am using the Swipe
gesture with CollectionView
, with Command Binding as follows:
<SwipeItem Command="{Binding SwipeRightCommand, Source={RelativeSource AncestorType={x:Type vm:MainPageViewModel}}}" CommandParameter="{Binding .}" />
The method relayed to by the bound command is as follows:
public async void OnSwipeRight(DataItemGroup groupItem)
{
if (groupItem == null) return;
await DataFolderActions(groupItem);
}
For the ContentPage XAML, the relevant attributes are defined as:
xmlns:vm="clr-namespace:MySample.ViewModels"
x:DataType="vm:MainPageViewModel"
Platform: .NET MAUI Android; Visual Studio: 17.5.0 Preview 1.0; Framework: 6.0.543.4
IN DEBUG MODE:
Everything works as expected and in the Method above, the Swipe CommandParameter is forwarded as non-null.
IN RELEASE MODE:
I noted that the CommadParameter passed to the Method is now null
, hence the Binding doesn't work as expected.
CHANGED BINDING FOR CommandParameter:
To overcome the above issue, I tried to change the Binding for the CommandParameter as follows:
<SwipeItem Command="{Binding SwipeRightCommand, Source={RelativeSource AncestorType={x:Type vm:MainPageViewModel}}}" CommandParameter="{Binding Source={RelativeSource Self}, Path=BindingContext}" />
Now the above works both for Debug and Release modes. The difference in the Binding is now for CommandParameter as summarised below:
CommandParameter="{Binding .}"
CommandParameter="{Binding Source={RelativeSource Self}, Path=BindingContext}"
The second alternative Binding which I came across as a suggested solution for a similar question, but gives no explanation. What I couldn't be sure is therefore how the above two codes can be different under Debug and Release mode.
What is the explanation for code #1 to work in Debug but fail in Release mode?
Put differently, how are the two codes different to produce different operational results?
PS: I am adding the dotnet-maui Tag just in case there are peculiarities arising from .NET MAUI to contribute to this issue For example, I've noticed Swipe gesture issues with CollectionView
under WinUI and therefore couldn't rule in or rule out the .NET MAUI effect.