【问题标题】:How to add an DataBound Event Handler to a ListView in Xamarin Forms?如何将 DataBound 事件处理程序添加到 Xamarin 表单中的 ListView?
【发布时间】:2017-08-31 19:28:34
【问题描述】:

我在 xamarin 表单上使用绑定到 ListViewObservableCollection<T>。并想做一个空列表验证并显示label

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

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

【问题讨论】:

    标签: c# xaml listview xamarin xamarin.forms


    【解决方案1】:

    怎么样?

    <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>
    

    转换器是:

    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();
        }
    }
    

    【讨论】:

    • 没有像onDataBoundEvent 这样更简单的解决方案吗?
    猜你喜欢
    • 2023-04-03
    • 2014-08-03
    • 2021-02-26
    • 2018-08-24
    • 1970-01-01
    • 2017-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多