Wpf 在ItemsControl中分组后不显示项目
我已将分组添加到ItemsControl:Wpf 在ItemsControl中分组后不显示项目,wpf,grouping,itemscontrol,Wpf,Grouping,Itemscontrol,我已将分组添加到ItemsControl: <ItemsControl Style="{StaticResource SellingDashboardToDosList}" Grid.Row="2" BorderThickness="1" Background="#C7E8F8" HorizontalAlignment="Stretch" ItemsSource="{Binding ToDoList}" > <ItemsControl.G
<ItemsControl Style="{StaticResource SellingDashboardToDosList}" Grid.Row="2" BorderThickness="1" Background="#C7E8F8" HorizontalAlignment="Stretch" ItemsSource="{Binding ToDoList}" >
<ItemsControl.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<GroupBox Header="{Binding Name}">
<ItemsPresenter />
</GroupBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ItemsControl.GroupStyle>
</ItemsControl>
现在我只看到空的分组框。我使用Snoop工具浏览了这个应用程序,发现GroupBox ItemPresenter是空的!原因可能是什么
如果我从ItemsControl(ItemsControl.GroupStyle元素)中删除分组,那么一切正常,我将再次看到所有项目。我不需要对基础数据上下文进行任何更改就可以查看所有项。数据上下文(ItemsSource binging)的类型为CollectionViewSource
绑定跟踪已打开,但我没有看到任何绑定错误。您必须首先对数据进行分组。使用CollectionViewSource可以执行以下操作:
<CollectionViewSource x:Key="Data" Source="{StaticResource SellingDashboardToDosList}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="PropertyNameToGroupBy"/>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
只有这样,您才能执行以下操作:
<ItemsControl ItemsSource="{Biding Source={StaticResource Data}}" ...
似乎ItemsControl样式覆盖了ItemsControl.Template属性。一旦该样式被覆盖,问题就解决了。样式对我来说适用于示例数据。请看一下分组字段数据。我应该查找什么?现在,组的ItemsPresenter是空的。为什么?你能上传一些你用一些数据尝试过的示例代码吗?这不能很快完成。稍后我将尝试这样做。数据上下文是CollectionViewSource,只是它是在C#而不是XAML中生成的。很抱歉没有早点提到。谢谢你愿意帮忙。问题在于样式,而不是数据源。为了完成解决方案,最好使用正确的“ItemsPanelTemplate”设置“ItemsPanel”,而不是覆盖ItemControl模板。