When debugging, everything is transferred correctly and the method for deleting images works fine, but in the release version I encountered a problem that ImageSource is not transferred, what could this be related to?
<StackLayout>
<CollectionView
ItemsSource="{Binding SelectedImageList}"
VerticalOptions="Fill"
HorizontalOptions="Fill"
SelectionMode="Single"
HorizontalScrollBarVisibility="Never">
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame
Padding="-1"
Margin="10,5,0,0"
BackgroundColor="Transparent">
<Grid>
<Image
Source="{Binding .}"
Aspect="AspectFill"
HeightRequest="50"
WidthRequest="50" InputTransparent="True"
/>
<Image Source="cross.svg" Aspect="Fill" WidthRequest="17" HeightRequest="17" HorizontalOptions="End" Margin="2" VerticalOptions="Start"/>
</Grid>
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type vm:ChatWIndowViewModel}}, Path=RemoveImageCommand}" CommandParameter="{Binding }"/>
</Frame.GestureRecognizers>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
public void RemoveImage(ImageSource image)
{
SelectedImageList.Remove(image);
if (SelectedImageList.Count == 0)
{
if (!EditMode)
{
IsImageSelected = false;
IsVisible = false;
}
else
{
EditImage = false;
}
}
}
I tried to call commands in different ways, made a call through a button and through a tapped button, but nothing helped
Assuming SelectedImageList
is a list of ImageSource, then specify x:Datatype for CollectionView’s DataTemplate as below
<DataTemplate x:DataType="ImageSource">
And also in command, It’s better to assume the parameter as object
and then check whether it’s an ImageSource
.
public void RemoveImage(object obj)
{
if(obj is ImageSource image)
SelectedImageList.Remove(image);
....
}