【发布时间】:2014-02-21 18:35:50
【问题描述】:
我有一个问题,我不知道该怎么办。我正在尝试制作一个简单的高分列表,我需要为每个分数获取数字 (1,2,3,4...)。
XAML:
<ListBox x:Name="ListBox" ItemsSource="{Binding Source.View}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ROW_NUMBER_HERE}"/>
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding Score}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
C#
public ObservableCollection<Item> Items { get; set; }
public System.Windows.Data.CollectionViewSource Source { get; set; }
public HighscorePage()
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
if (store.FileExists("highscores"))
{
using (IsolatedStorageFileStream stream = store.OpenFile("highscores", FileMode.Open))
{
var serializer = new DataContractSerializer(typeof(ObservableCollection<Item>));
Items = (ObservableCollection<Item>)serializer.ReadObject(stream);
}
}
if (Items != null)
{
Source = new System.Windows.Data.CollectionViewSource();
Source.Source = Items;
Source.SortDescriptions.Add(new SortDescription("Score", ListSortDirection.Descending));
}
InitializeComponent();
DataContext = this;
}
Items ObservableCollection 包含名称和分数数据。
我尝试使用正常的 while 循环来添加数字但没有成功。而且我也无法让 AlternationCount 工作。 wp7甚至支持吗?有什么想法吗?
谢谢!
【问题讨论】:
标签: c# xaml windows-phone-7 listbox