Wpf 选择DatagridColumnHeader将选择列表中的项目

Wpf 选择DatagridColumnHeader将选择列表中的项目,wpf,datagrid,Wpf,Datagrid,我有一个带有复选框的Datagrid。选中某个项目后,将选中该复选框并高亮显示该行。当我单击DataGridColumnHeader时,选中的项目会再次添加到DataGrid的SelectedItems上。因此,如果我当前有2个SelectedItems,如果我单击DataGridColumnHeader,SelectedItems计数将为4-添加的项目是所选项目的副本 我不知道为什么每次单击DataGridColumnHeader时SelectedItems都会更新。我的模型上有一个IsSel

我有一个带有复选框的Datagrid。选中某个项目后,将选中该复选框并高亮显示该行。当我单击DataGridColumnHeader时,选中的项目会再次添加到DataGrid的SelectedItems上。因此,如果我当前有2个SelectedItems,如果我单击DataGridColumnHeader,SelectedItems计数将为4-添加的项目是所选项目的副本

我不知道为什么每次单击DataGridColumnHeader时SelectedItems都会更新。我的模型上有一个IsSelected属性。我尝试调试以了解哪个正在更新选择,然后我得到以下外部代码:

PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.SetValue(object item, object value) + 0x1c5 bytes 
PresentationFramework.dll!System.Windows.Data.BindingExpression.UpdateSource(object value) + 0xce bytes 
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.UpdateValue() + 0xa9 bytes  
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Dirty() + 0x7a bytes    
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.SetValue(System.Windows.DependencyObject d, System.Windows.DependencyProperty dp, object value) + 0x3e bytes    
WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal) + 0x3b1 bytes  
WindowsBase.dll!System.Windows.DependencyObject.SetCurrentValueInternal(System.Windows.DependencyProperty dp, object value) + 0x99 bytes    
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.AdjustNewContainers() + 0x11d bytes   
PresentationFramework.dll!System.Windows.Controls.ItemContainerGenerator.SetStatus(System.Windows.Controls.Primitives.GeneratorStatus value) + 0xb0 bytes   
PresentationFramework.dll!System.Windows.Controls.ItemContainerGenerator.BatchGenerator.System.IDisposable.Dispose() + 0x22 bytes   
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(System.Windows.Size constraint, ref double? lastPageSafeOffset, ref System.Collections.Generic.List<double> previouslyMeasuredOffsets, bool remeasure) + 0x1e83 bytes  
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(System.Windows.Size constraint) + 0x106 bytes  
PresentationFramework.dll!System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(System.Windows.Size constraint) + 0x3b bytes 
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x313 bytes  
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x521 bytes  
PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout() + 0x569 bytes   
PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayoutCallback(object arg) + 0x22 bytes  
PresentationCore.dll!System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() + 0x96 bytes   
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget) + 0xdf bytes   
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandler(object resizedCompositionTarget) + 0x2f bytes   
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x5a bytes 
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler) + 0x47 bytes    
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() + 0x281 bytes 
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x285 bytes 
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x9 bytes   
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x57 bytes    
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0x71 bytes  
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() + 0x2e3 bytes    
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0xb3 bytes 
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x14a bytes   
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x80 bytes    
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x5a bytes 
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler) + 0x47 bytes    
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) + 0x2bc bytes 
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) + 0x140 bytes    
[Native to Managed Transition]  
[Managed to Native Transition]  
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) + 0x112 bytes 
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) + 0x17a bytes    
PresentationFramework.dll!System.Windows.Application.Run() + 0x67 bytes 
UpgradeStudio.exe!UpgradeStudio.App.Main() + 0x70 bytes C#
[Native to Managed Transition]  
[Managed to Native Transition]  
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x57 bytes  
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x285 bytes 
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x9 bytes   
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x57 bytes    
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x51 bytes   
[Native to Managed Transition]  
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.SetValue(对象项,对象值)+0x1c5字节
PresentationFramework.dll!System.Windows.Data.BindingExpression.UpdateSource(对象值)+0xce字节
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.UpdateValue()+0xa9字节
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Dirty()+0x7a字节
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.SetValue(System.Windows.DependencyObject d,System.Windows.DependencyProperty dp,object value)+0x3e字节
WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp,对象值,System.Windows.PropertyMetadata元数据,bool强制WithDeferedReference,bool强制WithCurrentValue,System.Windows.OperationType OperationType,bool isInternal)+0x3b1字节
WindowsBase.dll!System.Windows.DependencyObject.SetCurrentValueInternal(System.Windows.DependencyProperty dp,对象值)+0x99字节
PresentationFramework.dll!System.Windows.Controls.Primitives.Selector.AdjustNewContainers()+0x11d字节
PresentationFramework.dll!System.Windows.Controls.ItemContainerGenerator.SetStatus(System.Windows.Controls.Primitives.GeneratorStatus值)+0xb0字节
PresentationFramework.dll!System.Windows.Controls.ItemContainerGenerator.BatchGenerator.System.IDisposable.Dispose()+0x22字节
PresentationFramework.dll!System.Windows.Controls.VirtualzingStackPanel.MeasureOverrideImpl(System.Windows.Size约束,ref double?lastPageSafeOffset,ref System.Collections.Generic.List PreviouslyMeasureRedOffset,bool remeasure)+0x1e83字节
PresentationFramework.dll!System.Windows.Controls.VirtualzingStackPanel.MeasureOverride(System.Windows.Size constraint)+0x106字节
PresentationFramework.dll!System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(System.Windows.Size constraint)+0x3b字节
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)+0x313字节
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)+0x521字节
PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout()+0x569字节
PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayoutCallback(对象arg)+0x22字节
PresentationCore.dll!System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()+0x96字节
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandlerCore(对象大小调整的CompositionTarget)+0xdf字节
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandler(对象大小调整的CompositionTarget)+0x2f字节
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate回调,对象args,int numArgs)+0x5a字节
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源、系统.Delegate方法、对象args、int numArgs、系统.Delegate catchHandler)+0x47字节
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl()+0x281字节
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext ExecutionContext,System.Threading.ContextCallback回调,对象状态,bool preserveSyncCtx)+0x285字节
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext ExecutionContext,System.Threading.ContextCallback回调,对象状态,bool preserveSyncCtx)+0x9字节
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext ExecutionContext,System.Threading.ContextCallback回调,对象状态)+0x57字节
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke()+0x71字节
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue()+0x2e3字节
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd,int msg,System.IntPtr wParam,System.IntPtr lParam,ref bool handled)+0xb3字节
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd,int msg,System.IntPtr wParam,System.IntPtr lParam,ref bool handled)+0x14a字节
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(对象o)+0x80字节
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate回调,对象args,int numArgs)+0x5a字节
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源、系统.Delegate方法、对象args、int numArgs、系统.Delegate catchHandler)+0x47字节
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority,System.TimeSpan超时,System.Delegate方法,对象args,int numArgs)+0x2bc字节
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd,int msg,System.IntPtr wParam,System.IntPtr lParam)+0x140字节
[本机到托管转换]
[管理到本机转换]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame框架)+0x112字节
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Wind