0
我是Windows Phone 7開發的全新產品,幾乎和Silverlight一樣新。我有一個DataTemplate,StackPanel的一個列表框,和的TextBlocks像這樣:將列動態添加到列表框
<ListBox Height="355" HorizontalAlignment="Left" Margin="6,291,0,0" Name="detailsList" VerticalAlignment="Top" Width="474" Background="#36FFFFFF">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Width="50" Text="{Binding Ticker}" />
<TextBlock Width="50" Text="{Binding Price}" />
<TextBlock Width="50" Text="{Binding GainLoss}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我有一些C#代碼來填充它:
var info = new List<StockInfo>();
info.Add(new StockInfo { Ticker = "C", Price = "5.18", GainLoss = "10" });
info.Add(new StockInfo { Ticker = "WEN", Price = "4.18", GainLoss = "12" });
info.Add(new StockInfo { Ticker = "CBB", Price = "5.22", GainLoss = "210" });
detailsList.ItemsSource = info;
而這一切工作正常。我的問題是:如何動態地(在運行時)向列表框中添加/刪除附加的「文本塊」?另外,如何將列標題放在列表框中?