C# 中的 WinPhone 8 项目。我正在尝试填充分组列表。组标题出现,项目不出现。相关代码为:
class MyPage
{
public class Group : IGrouping<string, string>
{
public string Title{get;set;}
public string[] Items;
public string Key
{
get { return Title; }
}
public IEnumerator<string> GetEnumerator()
{
return (Items as IEnumerable<string>).GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return Items.GetEnumerator();
}
}
private Group[] m_ItemGroups =
{
new Group(){Title = "A", Items = new string[] {"A", "ASA"}},
new Group(){Title = "X", Items = new string[] {"X", "XX"}},
};
private void OnLoaded(object sender, RoutedEventArgs e)
{
TheList.ItemsSource = m_ItemGroups;
}
}
和 XAML:
<phone:LongListSelector
x:Name="TheList"
Grid.Row="1"
IsGroupingEnabled="True"
SelectionChanged="OnSelChanged"
>
<phone:LongListSelector.GroupHeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}"
Style="{StaticResource PhoneTextGroupHeaderStyle}"
Foreground="{StaticResource PhoneForegroundBrush}" />
</DataTemplate>
</phone:LongListSelector.GroupHeaderTemplate>
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Orientation="Horizontal">
<TextBlock Text="Hello world" TextWrapping="Wrap" Width="345"/>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
这两种方法都没有GetEnumerator()
被调用。Key
getter 也永远不会被调用。看起来该列表无法将我的Group
类识别为它的字符串集合。请问,这里有什么问题吗?
项目模板很好。当我将列表更改为非分组时,我看到两个带有虚拟文本的项目。
用自定义类替换string
作为项目类型没有帮助。