2013-12-11 17 views
1

我想知道如何從ListBox中的URL和顯示加載多個數據..加載多個內容來自[]數組中的列表框在WP8

我的班級組織..

public class Organization : BaseModel 
    { 

     public int id {get;set;} 
     public string address {get;set;} 
     public string city { get; set; } 
     public string contact1 {get; set;} 
     public string contact2 {get; set;} 
     public string country {get; set;} 
     public string description {get; set;} 
     public Event[] events {get; set;}//Need to load the Event data in listbox 
} 

我的事件[]類..

public class Events: BaseModel 
{ 
     public int id { get; set; } 
     public DateTime event_date { get; set; } 
     public string event_day { get; set; } 
     public string event_location { get; set; } 
     public DateTime event_time { get; set; } 
} 

我需要加載Event[]數據到列表框中的任何一個可以幫助我解決這個問題..

在此先感謝..

+1

爲什麼不使用列表或數組中的集合? –

回答

1

如果你沒有使用數據綁定,只是想顯示在列表框中的事件屬性那麼這將是:

foreach (var Event in Events) 
{ 
    listBox1.Items.Add(Event); 
} 

//and in the ListBox, specify which property of Event to be displayed 
<ListBox x:Name="listBox1" DisplayMemberPath="Name"/> 

或者我可以在這個問題失去了一些東西,因爲它似乎過於直截了當..

UPDATE: 要你需要,而不是指定的簡單設置的DisplayMemberPath ItemTemplate中的每個列表框中顯示的項目不止一個屬性值。例如:

<ListBox x:Name="listBox1"> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Horizontal" > 
       <TextBlock Text="{Binding name}" Margin="0,0,10,0"/> 
       <TextBlock Text="{Binding address}"/> 
      </StackPanel> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 
+0

感謝你..它的工作原理..我的單值有近7個數據..所以我可以成功地獲得單個數組[]值..但我需要提取array..eg的所有值:Array [0 ] = { 「姓名」, 「ID」, 「地址」,..},陣列[1] = { 「姓名」, 「ID」, 「地址」,..},陣列[2] = { 「名稱」 ,「ID」,「地址」,..},.. –

+0

我不明白你的意思,所以你有二維數組?這意味着與你所提到的問題不同的問題。或者你只是想在ListBox中顯示Event的所有屬性,而不是隻顯示一個? – har07

+0

我需要顯示事件[] –

0

而不是使用

public Event[] Events {get; set;} 

使用

public List<Event> Events {get; set;} 

添加項目到您的清單,

Events.Add(new Events 
{ 
    id = 1, 
    event_day = today 
}); 

並將其綁定與

列表框
listbox.itemsource = Events;