gpt4 book ai didi

c# - ListCollectionView.GroupDescriptions.Clear() 抛出 argumentnullexception

转载 作者:太空宇宙 更新时间:2023-11-03 12:36:42 28 4
gpt4 key购买 nike

所以我有一个非常简单的数据网格,其组样式如下:

 <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() 方法上遇到异常。这是完整的异常(exception):

    {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 绑定(bind)到一个以 observablecollection 作为源的 ListCollectionView。

如果我用这个替换控件模板中的扩展器:

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

然后一切都恢复正常了。我看不出我在做什么不寻常的事……谁能发现我遗漏的东西?

谢谢!

最佳答案

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

如本 MaterialDesignXamlToolkit bug report 中所述,异常是由 Tag 属性 上的 DoubleAnimation 引起的。

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

关于c# - ListCollectionView.GroupDescriptions.Clear() 抛出 argumentnullexception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40679953/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com