我想通过WCF服务填充长列表。编译没有错误,但执行程序的结果看起来像三行:PhoneApp1.ServiceReference1.worker
而不是我想要显示的名称和其他数据。我的服务实现是:
public IEnumerable<worker> GetStuffList()
{
List<worker> stuffList = new List<worker>();
stuffList.Add(new worker("John", 23, true));
stuffList.Add(new worker("Nick", 22, true));
stuffList.Add(new worker("Gill", 23, false));
return stuffList;
}
private List<Group<worker>> GetStuffEnumerable()
{
IEnumerable<worker> stuffList = GetStuffList();
return GetItemGroups(stuffList, c => c.Age.ToString());
}
private static List<Group<T>> GetItemGroups<T>(IEnumerable<T> itemList, Func<T, string> getKeyFunc)
{
IEnumerable<Group<T>> groupList = from item in itemList
group item by getKeyFunc(item) into g
orderby g.Key
select new Group<T>(g.Key, g);
return groupList.ToList();
}
public class Group<T> : List<T>
{
public Group(string name, IEnumerable<T> items)
: base(items)
{
this.Title = name;
}
public string Title
{
get;
set;
}
}
答案 0 :(得分:1)
您需要为LongListSelector指定ItemTemplate。没有它,它显示object.ToString()。
这样的事情:
<LonglistSelector ...>
<LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</LongListSelector.ItemTemplate>
</LongListSelector/>