错误提示:这是绑定后通过按钮事件查看itemsource时发现的(这是一个好方法,可以对obser collection检查)
程序集“mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”中的泛型类型“System.Collections.Generic.ICollection`1”所用的泛型参数数目不正确。
<local:VariableGridView.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal"/>
<VariableSizedWrapGrid VerticalAlignment="Top" ItemHeight="250" ItemWidth="250" MaximumRowsOrColumns="2" />红色部分不应该用在此处,不分组就可以这样用
</ItemsPanelTemplate> </local:VariableGridView.ItemsPanel> <local:VariableGridView.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> <Grid Margin="1,0,0,6"> <TextBlock Text="{Binding GroupName}" Style="{StaticResource SubheaderTextStyle}"/> </Grid> </DataTemplate> </GroupStyle.HeaderTemplate> <GroupStyle.Panel> <ItemsPanelTemplate> <VariableSizedWrapGrid Orientation="Vertical" MaximumRowsOrColumns="2" ItemHeight="250" ItemWidth="250" /> <!--<VariableSizedWrapGrid Orientation="Vertical" MaximumRowsOrColumns="2" Margin="0,0,30,0"/>--> </ItemsPanelTemplate> </GroupStyle.Panel> </GroupStyle> </local:VariableGridView.GroupStyle>
归根到底是分组产生的问题,分组时,对应的面板设置要变成VirtualizingStackPanel ,同时 GroupStyle 要设置成这样
<GroupStyle.Panel> <ItemsPanelTemplate> <VariableSizedWrapGrid Orientation="Vertical" MaximumRowsOrColumns="2" ItemHeight="250" ItemWidth="250" /> <!--<VariableSizedWrapGrid Orientation="Vertical" MaximumRowsOrColumns="2" Margin="0,0,30,0"/>--> </ItemsPanelTemplate> </GroupStyle.Panel>