2014-06-22 105 views
0

我想通過WCF服務填充longlist。彙編沒有錯誤,但執行的程序的結果看起來像這樣的三行:PhoneApp1.ServiceReference1.worker而不是我想要顯示的名稱和其他數據。我的服務實施是:Longlist沒有正確創建

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

回答

1

您需要爲LongListSelector定義一個ItemTemplate。沒有它,它顯示object.ToString()。

事情是這樣的:

<LonglistSelector ...> 
    <LongListSelector.ItemTemplate> 
     <DataTemplate> 
      <StackPanel> 
       <TextBlock Text="{Binding Name}"/> 
      </StackPanel> 
     </DataTemplate>   
    </LongListSelector.ItemTemplate> 
</LongListSelector/>