【发布时间】:2013-10-20 01:58:31
【问题描述】:
下面的绑定是在一个 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();
}
}
}
【问题讨论】:
-
当然。它没有用。 :) 应该这样吗?
-
我很困惑。你在哪里声明
activity改变了?当您的 xaml 没有引用它时,为什么所有这些关于ActivityStream的代码? -
ActivityStream 充满了 API 调用的内容......我的 ActivityStream 数据合约处理返回的所有位和 bobs(并且该类来自 json 到 c# 工具)。 ActivityStream是一个ListBox绑定,上面是ActivityStream子属性的数据模板;其中之一是活动。希望对你有帮助
标签: c# xaml windows-phone-8