Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 分组的LongListSelector:显示标题,项不';T_C#_Silverlight_Windows Phone_Windows Phone 8_Longlistselector - Fatal编程技术网

C# 分组的LongListSelector:显示标题,项不';T

C# 分组的LongListSelector:显示标题,项不';T,c#,silverlight,windows-phone,windows-phone-8,longlistselector,C#,Silverlight,Windows Phone,Windows Phone 8,Longlistselector,C#中的WinPhone 8项目。我正在尝试填充一个分组列表。显示组标题,但不显示项目。有关守则如下: class MyPage { public class Group : IGrouping<string, string> { public string Title{get;set;} public string[] Items; public string Key { ge

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;
    }
}
classmypage
{
公共类组:iGroup
{
公共字符串标题{get;set;}
公共字符串[]项;
公共字符串密钥
{
获取{返回标题;}
}
公共IEnumerator GetEnumerator()
{
返回(项为IEnumerable).GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
返回项。GetEnumerator();
}
}
私有组[]m_项目组=
{
新组(){Title=“A”,Items=新字符串[]{“A”,“ASA”},
新组(){Title=“X”,Items=新字符串[]{“X”,“XX”},
};
已加载专用void(对象发送方,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也不会被调用。列表似乎无法将my
Group
类识别为它所属的字符串集合。拜托,这里怎么了

项目模板很好。当我将列表更改为非分组时,我会看到两个带有伪文本的项


字符串
替换为自定义类的项目类型没有帮助。

看起来像
LongListSelector
希望在分组模式下,
ItemsSource
集合中的对象实现
System.Collections.IList
(非类型化)。一个简单的
IEnumerator
是不行的


我希望那是有记录的。到目前为止,WP8 SDK文档非常糟糕。

Seva是正确的,Microsoft更改了您在分组模式下分配给
LongListSelector
ItemsSource
的类型要求

您需要将用于分组项目的任何类从继承
IEnumerable
转换为仅继承
List

实际上,这很简单,这就是可以与WP8LongListSelector一起使用的组类示例:

    public class Group<T> : List<T>
{
    public Group(char name, IEnumerable<T> items) : base(items)
    {
        this.Letter = name;

    }



    public char Letter
    {
        get;
        set;
    }


}
公共类组:列表
{
公共组(字符名,IEnumerable项):基本(项)
{
这个字母=名字;
}
公函
{
得到;
设置
}
}

我现在也有同样的问题。您可以发布IList的实现吗?毕竟我使用了一个ObservableCollection的ObservableCollection。没有手动实现IList。@SevaAlekseyev我也有同样的问题,你能帮我解决吗