是否可以显示列表框的第一个元素,而不是为 xaml 创建数据模板
本文关键字:xaml 创建 数据 显示 列表 元素 第一个 是否 | 更新日期: 2023-09-27 18:36:15
>以下绑定位于 IEnumerable 调用的活动上。问题是,在我的xaml...我只想输出数组中的第一个元素。你能按照这些思路做点什么吗:
<Run Text="{Binding activity[0].created_by.name}"></Run>
还是必须为活动 IEnumerable 数组链接另一个数据模板?
这是 ActivityStream 类的属性(我现在注意到它是一个列表。嗯。
...
[DataMember]
public List<object> activity { get; set; }
...
这是我做的地方 财产改变了 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 有一个 .第一个属性,你可以附在上面吗?
你的代码工作...通常:)。
你能展示一下你如何填充你的收藏吗?我认为这可能是因为您没有触发 INotifyPropertyChanged(或类似 INotify-like for collection)事件