1
我一直在尝试使用LongListSelector来获得最基本的分组示例,但只看到我的第一组。LongListSelector只显示1个组
这是我的XAML:
<toolkit:LongListSelector x:Name="MainListBox" Background="Transparent"
ItemsSource="{Binding Items}">
<toolkit:LongListSelector.GroupHeaderTemplate>
<DataTemplate>
<Border Background="Transparent">
<Border Background="{StaticResource PhoneAccentBrush}" Width="475" Height="35" HorizontalAlignment="Left">
<TextBlock Text="{Binding Key}"
Foreground="{StaticResource PhoneForegroundBrush}"
Style="{StaticResource PhoneTextGroupHeaderStyle}"
VerticalAlignment="Bottom"/>
</Border>
</Border>
</DataTemplate>
</toolkit:LongListSelector.GroupHeaderTemplate>
<toolkit:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Orientation="Horizontal">
<TextBlock Text="{Binding name}" TextWrapping="Wrap" Width="345"/>
</StackPanel>
</DataTemplate>
</toolkit:LongListSelector.ItemTemplate>
</toolkit:LongListSelector>
这里是我的C#代码:
List<ItemViewModel> l1 = new List<ItemViewModel>();
List<ItemViewModel> l2= new List<ItemViewModel>();
l1.Add(new ItemViewModel(){ name="test1" });
l1.Add(new ItemViewModel(){ name="test2" });
l2.Add(new ItemViewModel(){ name="test3" });
this.Items.Add(new Group<ItemViewModel>("A", l1));
this.Items.Add(new Group<ItemViewModel>("B", l2));
ItemViewModel仅仅是一个容器类。
当我运行代码,我主要看:
B.
的
test1的
test2的
,但没有签署任何帮助表示赞赏。
组被定义为:
public class Group<T> : ObservableCollection<T>
{
public Group(string name, IEnumerable<T> items)
{
this.Key = name;
foreach (T item in items)
{
this.Add(item);
}
}
public override bool Equals(object obj)
{
Group<T> that = obj as Group<T>;
return (that != null) && (this.Key.Equals(that.Key));
}
public string Key
{
get;
set;
}
}
尽量分别结合在模板中的组属性。如果你这样做了,你可以发布模板吗? [这里](http://www.windowsphonegeek.com/articles/wp7-longlistselector-in-depth--part1-visual-structure-and-api)是一个基本的例子,如果这是你第一次尝试'longlistselector' – abhinav
感谢您的回复,更新了上面的帖子以包含完整的xaml(希望这就是您所指的)。如前所述,我看到1个GroupHeader和下面的2个项目......只是不是第二组和它的项目。 – user1053873
已解决 - 问题在于xaml中的绑定。而不是这样做,我需要以编程方式设置MainListBox.ItemsSource。 – user1053873