点击十字图像时,我需要删除所选的图片。为此,我在图像上方添加了十字图像并添加了点击事件。我正在android.telecom.Connection
中显示图像。
MainPage.xaml
FlowListView
MainPage.xaml.cs
<flv:FlowListView FlowColumnCount="3" x:Name="listItems"
SeparatorVisibility="None"
HasUnevenRows="false" RowHeight="100" >
<flv:FlowListView.FlowColumnTemplate>
<DataTemplate >
<StackLayout
Orientation="Vertical">
<Image
Source="ic_close.png"
HeightRequest="20"
ClassId="{Binding .}"
WidthRequest="20">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="RemoveImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Image AbsoluteLayout.LayoutFlags="All" HeightRequest="100" AbsoluteLayout.LayoutBounds="0,0,1,1" Source="{Binding .}" Aspect="AspectFill" HorizontalOptions="FillAndExpand">
</Image>
</StackLayout>
</DataTemplate>
</flv:FlowListView.FlowColumnTemplate>
</flv:FlowListView>
有人,请提出一种从FlowListview中删除该图像的方法吗?
答案 0 :(得分:0)
首先,将您的收藏集设为ObservableCollection
ObservableCollection<string> _images = new ObservableCollection<string>();
第二,将图像名称添加到否则未使用的ClassID
属性中
<Image ClassID="{Binding .}" ... />
最后,在您的RemoveImage
public void RemoveImage(Object sender, EventArgs args)
{
var i = (Image)sender;
images.Remove(i.ClassID);
}
答案 1 :(得分:0)
创建一个ObservableCollection并在接收这些图像时将其添加到其中
喜欢这个:
protected override void OnAppearing()
{
base.OnAppearing(); :)
MessagingCenter.Subscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelected", (s, images) =>
{
for (int i =0;i< images.Count;i++)
{
_images.Add(images[i]);
}
listItems.FlowItemsSource = _images;
});
}
然后在点击图像后删除该选定图像。
public void RemoveImage(Object sender, EventArgs args)
{
Image image = sender as Image;
string obj = image.BindingContext as string;
_images.Remove(obj);
}