繁体   English   中英

您是否可以显示ListBox的第一个元素,而不是为xaml创建数据模板

[英]Can you display the first element of a ListBox rather than create a data template for xaml

以下绑定是基于IEnumerable的活动。 问题是,在我的xaml中...我只想输出数组中的第一个元素。 您可以按照以下方式做些什么:

<Run Text="{Binding activity[0].created_by.name}"></Run>

还是必须为活动IEnumerable数组链接另一个数据模板?

这是ActivityStream类的属性(我现在注意到它是一个List..hmm。)

...
    [DataMember]
    public List<object> activity { get; set; }
...

这是我在哪里做PropertyChanged yada yada的东西

    public IEnumerable<JamesStream> activityStream;

...

    private async void LoadActivityStreamSection()
    {
        activityStreamRepository = new JamesStreamRepository();
        var tempActivityStream = await activityStreamRepository.GetAllBySpaceId(space.space_id);

        activityStream = tempActivityStream;
        ActivityStream = null;

        //The Activitiy Stream has a property which is of type List<object> called activity
        // In my xaml I just want to be outputting the 1st entry of the List<object> property .created_by_name
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChangedEventHandler tempEvent = PropertyChanged;

        if (tempEvent != null)
        {
            // property changed
            tempEvent(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public IEnumerable<JamesStream> ActivityStream
    {
        get
        {
            return activityStream;
        }
        set
        {
            if (activityStream != value)
            {
                OnPropertyChanged();
            }
        }
    }

如果您的IEnumerable具有.First属性,您是否可以附加到该属性?

您的代码正常工作... :)。

您能说明如何填写您的收藏吗? 我认为这可能是因为您没有触发INotifyPropertyChanged(或类似INotify的集合)事件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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