简体   繁体   中英

MAUI Databinding with CommandParameter return null

<Grid Grid.Row="3">
    <CollectionView x:Name="collectionView" ItemsSource="{Binding GarbageCollectionModels}">
        <CollectionView.ItemTemplate>
            <DataTemplate x:DataType="{x:Type model:GarbageCollectionModel}">
                <Grid>
                    <Button x:DataType="vm:ConfiguratorViewModel"
                                Command="{Binding Source={RelativeSource AncestorType={x:Type vm:ConfiguratorViewModel}}, Path=DeleteInstanceCommand}"
                                CommandParameter="{Binding .}"/>

                </Grid>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
</Grid>
[RelayCommand]
private async void DeleteInstance(GarbageCollectionModel garbageCollection)
{
    SendTestText = JsonConvert.SerializeObject(garbageCollection);
}

Null will be returned after click the button. This only happens in Release mode and not in debug in Visual Studio 2022 prew. Everything is done on the android platform.

After changed to this code and rebuild solution, binding started working.

<DataTemplate x:DataType="model:GarbageCollectionModel">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM