Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Xamarin表单中将数据绑定事件处理程序添加到ListView?_C#_Xaml_Listview_Xamarin_Xamarin.forms - Fatal编程技术网

C# 如何在Xamarin表单中将数据绑定事件处理程序添加到ListView?

C# 如何在Xamarin表单中将数据绑定事件处理程序添加到ListView?,c#,xaml,listview,xamarin,xamarin.forms,C#,Xaml,Listview,Xamarin,Xamarin.forms,我正在xamarin表单上使用绑定到列表视图的ObservableCollection。并希望进行空列表验证并显示标签 当第一次添加、删除或绑定数据时,我需要在列表视图中添加一个“EventHandler” 添加和删除事件可以从observetecollection列表中获得。但是当列表第一次有界时没有事件 怎么样 <ListView.Triggers> <DataTrigger Binding="{Binding FilteredTasks, Converter={S

我正在xamarin表单上使用绑定到
列表视图的
ObservableCollection
。并希望进行空列表验证并显示
标签

当第一次添加、删除或绑定数据时,我需要在列表视图中添加一个“EventHandler”

添加和删除事件可以从
observetecollection
列表中获得。但是当列表第一次有界时没有事件

怎么样

<ListView.Triggers>
    <DataTrigger Binding="{Binding FilteredTasks, Converter={StaticResource EmptyCollectionToBoolConverter}}" Value="true" TargetType="ListView">
        <Setter Property="Header">
            <Label Text="Ooops, there is nothing there."/>
        </Setter>
    </DataTrigger>
</ListView.Triggers>

没有比
onDataBound
事件更简单的解决方案了?
public class EmptyCollectionToBoolConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is ICollection collection)
        {
            return collection.Count == 0;
        }
        return true;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}