分组LongListSelector:头出现,物品不 [英] Grouped LongListSelector: headers appear, items don't
问题描述
WinPhone 8项目在C#。我试图填充分组名单。该组头出现,物品没有。相关的代码是:
WinPhone 8 project in C#. I'm trying to populate a grouped list. The group headers appear, the items don't. The relevant code is:
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()
方法是调用。在键
的getter永远不会被调用,无论是。貌似列表不认我的组
类的字符串,它是集合。拜托,有什么不对吗?
Neither of the GetEnumerator()
methods is called. The Key
getter is never called, either. Looks like the list does not recognize my Group
class as a collection of strings that it is. Please, what's wrong here?
该项目模板是罚款。当我更改列表以非分组,我看到两个项目与虚拟文本。
The item template is fine. When I change the list to non-grouped, I see two items with dummy text.
更换字符串
作为项目类型与自定义类于事无补。
Replacing the string
as the item type with a custom class does not help.
推荐答案
看起来 LongListSelector
预计,在分组的模式,即的ItemsSource
集合中的对象实施 System.Collections.IList
(无类型) 。一个简单的的IEnumerator
不会做。
Looks like LongListSelector
expects, in grouped mode, that the objects in the ItemsSource
collection implement System.Collections.IList
(untyped). A simple IEnumerator
won't do.
我希望被记录在案。到目前为止,WP8 SDK文档吸大的时间。
I wish that was documented. So far, WP8 SDK docs suck big time.
这篇关于分组LongListSelector:头出现,物品不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!