ListCollectionView.GroupDescriptions.Clear()抛出argumentnullexception

时间:2016-11-18 14:50:00

标签: c# wpf datagrid grouping

所以我有一个非常简单的Datagrid,其中包含这样的groupstyle:

 <DataGrid AutoGenerateColumns="False" VirtualizingPanel.IsVirtualizingWhenGrouping="True" Grid.Row="1" ItemsSource="{Binding Path=AssetCodeView}" d:LayoutOverrides="LeftMargin, RightMargin, TopMargin, BottomMargin" d:DataContext="{d:DesignInstance viewModel:ElementAssetCodeBaseWrapper }">
        <DataGrid.Columns>
            <DataGridCheckBoxColumn Binding="{Binding Path=IsChecked}" Header="Vald?"/>
            <DataGridTextColumn Binding="{Binding Path=ElementAssetCodeBase.UniqueRoomNumber}" Header="Rumsnummer"/>
            <DataGridTextColumn Binding="{Binding Path=ElementAssetCodeBase.LevelName}" Header="Level"/>
            <DataGridTextColumn Binding="{Binding Path=ElementAssetCodeBase.SymbolName}" Header="Type name"/>
            <DataGridCheckBoxColumn Binding="{Binding Path=ElementAssetCodeBase.HasAssetCode,Mode=OneWay}" Header="Has Asset Code"/>
            <DataGridTextColumn Binding="{Binding Path=ElementAssetCodeBase.CreatedAssetCode}" Header="Created Asset Code"/>

        </DataGrid.Columns>
        <DataGrid.GroupStyle>
            <GroupStyle>
                <GroupStyle.ContainerStyle>
                    <Style TargetType="GroupItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type GroupItem}">
                                    <Expander>
                                        <Expander.Header>
                                            <StackPanel Orientation="Horizontal">
                                                <CheckBox Checked="GroupedCheckBox_Checked" Unchecked="GroupedCheckBox_UnChecked" Content="{Binding Path=Name,Mode=OneWay}"/>
                                                <TextBlock Text=" Antal: "/>
                                                <TextBlock Text="{Binding Path=ItemCount,Mode=OneWay}"/>
                                            </StackPanel>
                                        </Expander.Header>
                                        <ItemsPresenter/>
                                    </Expander>
                                    <!--<StackPanel Orientation="Horizontal">
                                        <CheckBox Checked="GroupedCheckBox_Checked" Unchecked="GroupedCheckBox_UnChecked" Content="{Binding Path=Name}"/>
                                        <TextBlock Text=" Antal: "/>
                                        <TextBlock Text="{Binding Path=ItemCount}"/>
                                    </StackPanel>-->
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </GroupStyle.ContainerStyle>
            </GroupStyle>
        </DataGrid.GroupStyle>
    </DataGrid> 

我使用组合框更新分组的属性。我第一次更改组合框(空GroupDescription)时一切都很好。 下次我在GroupDescriptions集合的Clear()方法上获得异常。这是完全例外:

    {System.ArgumentNullException: Värde får inte vara null.
Parameternamn: defaultOriginValue
   vid System.Windows.Media.Animation.DoubleAnimationBase.GetCurrentValue(Object defaultOriginValue, Object defaultDestinationValue, AnimationClock animationClock)
   vid System.Windows.Media.Animation.AnimationStorage.GetCurrentPropertyValue(AnimationStorage storage, DependencyObject d, DependencyProperty dp, PropertyMetadata metadata, Object baseValue)
   vid System.Windows.Media.Animation.AnimationStorage.EvaluateAnimatedValue(PropertyMetadata metadata, EffectiveValueEntry& entry)
   vid System.Windows.UIElement.EvaluateAnimatedValueCore(DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry& entry)
   vid System.Windows.DependencyObject.EvaluateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry, OperationType operationType)
   vid System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   vid System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   vid System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, Boolean isDetach, FrameworkElementFactory templateRoot)
   vid System.Windows.StyleHelper.ClearTemplateChain(HybridDictionary[] instanceData, FrameworkElement feContainer, FrameworkContentElement fceContainer, List`1 templateChain, FrameworkTemplate oldFrameworkTemplate)
   vid System.Windows.StyleHelper.ClearGeneratedSubTree(HybridDictionary[] instanceData, FrameworkElement feContainer, FrameworkContentElement fceContainer, FrameworkTemplate oldFrameworkTemplate)
   vid System.Windows.StyleHelper.DoTemplateInvalidations(FrameworkElement feContainer, FrameworkTemplate oldFrameworkTemplate)
   vid System.Windows.Controls.Control.OnTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   vid System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   vid System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   vid System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   vid System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   vid System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   vid System.Windows.StyleHelper.InvalidateContainerDependents(DependencyObject container, FrugalStructList`1& exclusionContainerDependents, FrugalStructList`1& oldContainerDependents, FrugalStructList`1& newContainerDependents)
   vid System.Windows.StyleHelper.DoStyleInvalidations(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle)
   vid System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle, Style& styleCache)
   vid System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   vid System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   vid System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   vid System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   vid System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   vid System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   vid System.Windows.FrameworkElement.UpdateStyleProperty()
   vid System.Windows.TreeWalkHelper.InvalidateStyleAndReferences(DependencyObject d, ResourcesChangeInfo info, Boolean containsTypeOfKey)
   vid System.Windows.TreeWalkHelper.OnResourcesChanged(DependencyObject d, ResourcesChangeInfo info, Boolean raiseResourceChangedEvent)
   vid System.Windows.FrameworkElement.OnAncestorChangedInternal(TreeChangeInfo parentTreeState)
   vid System.Windows.TreeWalkHelper.OnAncestorChanged(DependencyObject d, TreeChangeInfo info, Boolean visitedViaVisualTree)
   vid System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   vid MS.Internal.PrePostDescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   vid System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   vid System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   vid System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   vid System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   vid System.Windows.DescendentsWalker`1.StartWalk(DependencyObject startNode, Boolean skipStartNode)
   vid MS.Internal.PrePostDescendentsWalker`1.StartWalk(DependencyObject startNode, Boolean skipStartNode)
   vid System.Windows.TreeWalkHelper.InvalidateOnTreeChange(FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, Boolean isAddOperation)
   vid System.Windows.FrameworkElement.OnVisualParentChanged(DependencyObject oldParent)
   vid System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject oldParent)
   vid System.Windows.Media.Visual.RemoveVisualChild(Visual child)
   vid System.Windows.Media.VisualCollection.DisconnectChild(Int32 index)
   vid System.Windows.Media.VisualCollection.Clear()
   vid System.Windows.Controls.UIElementCollection.ClearInternal()
   vid System.Windows.Controls.Panel.ClearChildren()
   vid System.Windows.Controls.Panel.EnsureEmptyChildren(FrameworkElement logicalParent)
   vid System.Windows.Controls.Panel.OnItemsChangedInternal(Object sender, ItemsChangedEventArgs args)
   vid System.Windows.Controls.VirtualizingPanel.OnItemsChangedInternal(Object sender, ItemsChangedEventArgs args)
   vid System.Windows.Controls.Panel.OnItemsChanged(Object sender, ItemsChangedEventArgs args)
   vid System.Windows.Controls.ItemContainerGenerator.OnRefresh()
   vid System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
   vid System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)
   vid System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
   vid System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
   vid System.Collections.ObjectModel.ReadOnlyObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
   vid System.Collections.ObjectModel.ReadOnlyObservableCollection`1.HandleCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   vid System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   vid System.Collections.ObjectModel.ObservableCollection`1.ClearItems()
   vid System.Collections.ObjectModel.Collection`1.Clear()
   vid MS.Internal.Data.CollectionViewGroupInternal.Clear()
   vid System.Windows.Data.ListCollectionView.PrepareShaping()
   vid System.Windows.Data.ListCollectionView.PrepareLocalArray()
   vid System.Windows.Data.ListCollectionView.RefreshOverride()
   vid System.Windows.Data.CollectionView.RefreshInternal()
   vid System.Windows.Data.CollectionView.RefreshOrDefer()
   vid System.Windows.Data.ListCollectionView.OnGroupByChanged(Object sender, NotifyCollectionChangedEventArgs e)
   vid System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   vid System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   vid System.Collections.ObjectModel.ObservableCollection`1.ClearItems()
   vid System.Collections.ObjectModel.Collection`1.Clear()
   vid White.ProjectSpecific.NKSTools.AssetCode.UI.ViewModel.MainViewModel.UpdateGroupDescriptions() i C:\Revit Dev\PROJEKTUNIKA\NKS Tools\src\White.ProjectSpecific.NKSTools.AssetCode\White.ProjectSpecific.NKSTools.AssetCode.UI\ViewModel\MainViewModel.cs:rad 187
   vid White.ProjectSpecific.NKSTools.AssetCode.UI.ViewModel.MainViewModel.set_FilterType(FilterType value) i C:\Revit Dev\PROJEKTUNIKA\NKS Tools\src\White.ProjectSpecific.NKSTools.AssetCode\White.ProjectSpecific.NKSTools.AssetCode.UI\ViewModel\MainViewModel.cs:rad 172}

我的Datagrid绑定到一个ListCollectionView,它有一个observablecollection作为源。

如果我用控制模板替换扩展器:

 <StackPanel Orientation="Horizontal">
<CheckBox Checked="GroupedCheckBox_Checked" Unchecked="GroupedCheckBox_UnChecked" Content="{Binding Path=Name}"/>
     <TextBlock Text=" Antal: "/>
     <TextBlock Text="{Binding Path=ItemCount}"/>
</StackPanel>

然后一切都恢复正常。 我无法看到我做任何与众不同的事情...... 谁能发现我错过的东西?

谢谢!

1 个答案:

答案 0 :(得分:0)

由于 DoubleAnimation ,我遇到了类似的问题,因此我尝试重现此异常。

如此MaterialDesignXamlToolkit bug report所述,异常是由标记属性上的DoubleAnimation引起的。

MaterialDesignExpander样式these changes之后,问题不再出现。

相关问题