问题描述
限时送ChatGPT账号..我正在尝试将 LongListSelector 与 CollectionView 结合使用.似乎 CollectionView 拥有所需的所有东西",但是当我将两者连接起来时,什么也没有发生.这是我到目前为止所拥有的:
I am trying to use LongListSelector in conjunction with CollectionView. It seems like CollectionView has all the "stuff" needed, but when I connect the two, nothing happens. Here's what I have so far:
在我的控件的构造函数(包含 LLS 的那个人)中,我构造了 CollectionView:
In my control's ctor (the guy that contains the LLS), I construct the CollectionView:
GroupDescription group = new PropertyGroupDescription("FullName", new FirstLetterConverter(true, true));
m_view.GroupDescriptions.Add(group);
然后,每当相关的依赖属性(包含我想放入 LLS 的列表的那个)发生变化时,我就会将其分配给 m_view 并将组分配给 ItemsSource:
Then, whenever the relevant dependency property (the one that contains the list I want to put in the LLS) changes, I go and assign that to m_view and assign the groups to ItemsSource:
private void FriendsChanged()
{
m_view.Source = Friends;
friendList.ItemsSource = m_view.View.Groups;
当我检查 .Groups 属性时,信息似乎是 kosher 的 - 它有正确数量的项目,并且每个项目都有似乎正确的子项目.但是,看起来一切都是内部的,因此 LLS 似乎无法显示相关信息.当我用模拟集合替换 CollectionView 内容时,LLS 会显示信息(因此我非常确信 LLS 设置正确)
When I inspect the .Groups property, the information seems to be kosher - it has the right amount of items and each item has child-items that seem to be correct. However, it looks like everything is internal and as such the LLS seems to be unable to display the relevant info. When I replace the CollectionView stuff with a mock collection, the LLS does show information (so I am pretty confident that the LLS is set up correctly)
以下是我在 LLS 中使用的内容 - 请注意,我在几个地方使用了XXXX"而不是绑定,以确保不会因绑定错误而以某种方式破坏:
Here's what I am using with the LLS - note that instead of binding, I use "XXXX" in a few places to make sure that nothing is somehow breaking because of faulty binding:
<toolkit:LongListSelector x:Name="friendList">
<toolkit:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding ThumbnailImage}" Width="62" Height="62"/>
<TextBlock Text="{Binding FullName}"/>
</Grid>
</DataTemplate>
</toolkit:LongListSelector.ItemTemplate>
<toolkit:LongListSelector.GroupHeaderTemplate>
<DataTemplate>
<Border Background="{StaticResource PhoneAccentBrush}" Padding="{StaticResource PhoneTouchTargetOverhang}" Width="200" HorizontalAlignment="Left">
<!--<TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}"/>-->
<TextBlock Text="XXXX" Style="{StaticResource PhoneTextLargeStyle}"/>
</Border>
</DataTemplate>
</toolkit:LongListSelector.GroupHeaderTemplate>
<toolkit:LongListSelector.GroupItemTemplate>
<DataTemplate>
<Border Background="{StaticResource PhoneAccentBrush}" Margin="{StaticResource PhoneTouchTargetOverhang}" Padding="{StaticResource PhoneTouchTargetOverhang}" Width="180">
<TextBlock Text="XXXX" Style="{StaticResource PhoneTextLargeStyle}"/>
<!--<TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}"/>-->
</Border>
</DataTemplate>
</toolkit:LongListSelector.GroupItemTemplate>
</toolkit:LongListSelector>
推荐答案
我遇到了同样的问题.LongListSelector 似乎不适用于 CollectionView.我通过将其绑定到 ObservableCollection 来解决这个问题.我花了两天时间弄清楚为什么 LongListSelector 没有显示任何项目.奇怪的是 CollectionView.IsEmpty 可以用来改变可见性(当然是通过转换器).但是不能显示项目.
I had the same problem. It seems LongListSelector doesn't work with CollectionView. I solve the issue by binding it to an ObservableCollection instead. I spent two days figuring out why LongListSelector wasn't showing any item. The strange thing is that CollectionView.IsEmpty works for to turn the Visibility (thru a Converter of course). But it doesn't work to show the items.
这篇关于是否可以将 CollectionView 与 LongListSelector 一起使用进行分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论