2012-12-13 3 views
4

DataGrid를 아래로 스크롤하려고하면 InvalidOperationException이 발생합니다. "바인딩 식은 이미 BindingGroup에 속하므로 다른 BindingGroup에 추가 할 수 없습니다 BindingGroup "이라고합니다. 사용중인 BindingGroups에 대해 알지 못하므로 어떤 내용인지 잘 모르겠습니다. 아래 컬럼만으로 좁혀졌습니다. 나는 또한 가상화와 관련이 있다고 생각한다. 어떤 아이디어? 예외의 스택 트레이스 여기스크롤 할 때 InvalidOperationException DataGrid : 바인딩식이 이미 BindingGroup에 속해 있습니다.

<DataGrid x:Name="dgStudentSNP" 
       AutoGenerateColumns="False" 

       Grid.Row="1" Margin="6,10" 
       HorizontalAlignment="Stretch" 
       HeadersVisibility="Column" 
       CanUserSortColumns="True" 
       CanUserAddRows="False" 
       CanUserResizeColumns="True" 
       CanUserDeleteRows="False" 
       BorderThickness="1" 
       SelectedValuePath="SNPEnrollmentID" VerticalScrollBarVisibility="Auto" VerticalAlignment="Top" Height="Auto" IsReadOnly="True"> 
      <DataGrid.Columns> 
       <DataGridTemplateColumn Header="Student Name" MinWidth="120"> 
        <DataGridTemplateColumn.CellTemplate> 
         <DataTemplate> 
          <TextBlock> 
            <Hyperlink Click="GetStudentFamily" > 
             <Run> 
              <Run.Text > 
               <MultiBinding StringFormat="{}{0} {1}"> 
                <Binding Path="FirstName"/> 
                <Binding Path="LastName" /> 
               </MultiBinding> 
              </Run.Text>                
             </Run> 
            </Hyperlink> 
          </TextBlock> 
         </DataTemplate> 
        </DataGridTemplateColumn.CellTemplate> 
       </DataGridTemplateColumn> 
       </DataGrid.Columns> 
      </DataGrid> 

됩니다 :

Stack Trace : at System.Windows.Data.BindingExpressionBase.JoinBindingGroup(BindingGroup bg, Boolean explicitJoin) 
    at System.Windows.Data.BindingExpressionBase.RejoinBindingGroup(Boolean isReflective, DependencyObject contextElement) 
    at System.Windows.Data.BindingExpression.OnDataContextChanged(DependencyObject contextElement) 
    at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) 
    at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) 
    at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) 
    at System.Windows.Data.MultiBindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) 
    at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) 
    at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs) 
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) 
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 
    at System.Windows.TreeWalkHelper.OnInheritablePropertyChanged(DependencyObject d, InheritablePropertyChangeInfo info) 
    at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d) 
    at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d) 
    at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren) 
    at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d) 
    at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d) 
    at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d) 
    at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren) 
    at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren) 
    at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d) 
    at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d) 
    at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe) 
    at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d) 
    at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren) 
    at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d) 
    at System.Windows.DescendentsWalker`1.StartWalk(DependencyObject startNode, Boolean skipStartNode) 
    at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) 
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 
    at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) 
    at System.Windows.Controls.ContentPresenter.OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
    at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) 
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 
    at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp) 
    at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange) 
    at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange) 
    at System.Windows.Data.BindingExpression.Activate(Object item) 
    at System.Windows.Data.BindingExpression.OnDataContextChanged(DependencyObject contextElement) 
    at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) 
    at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) 
    at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) 
    at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs) 
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) 
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 
    at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) 
    at System.Windows.Controls.ItemContainerGenerator.LinkContainerToItem(DependencyObject container, Object item, Boolean isRecycled) 
    at System.Windows.Controls.ItemContainerGenerator.OnItemReplaced(Object oldItem, Object newItem, Int32 index) 
    at System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args) 
    at System.Windows.Controls.ItemContainerGenerator.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e) 
    at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list) 
    at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args) 
    at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args) 
    at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e) 
    at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) 
    at System.Windows.Controls.ItemCollection.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e) 
    at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list) 
    at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args) 
    at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args) 
    at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) 
    at System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs args, Int32 adjustedOldIndex, Int32 adjustedNewIndex) 
    at System.Windows.Data.ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args) 
    at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args) 
    at System.Windows.Controls.MultipleCopiesCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e) 
    at System.Windows.Controls.MultipleCopiesCollection.set_CopiedItem(Object value) 
    at System.Windows.Controls.Primitives.DataGridCellsPresenter.OnItemChanged(Object oldItem, Object newItem) 
    at System.Windows.Controls.DataGridRow.OnItemChanged(Object oldItem, Object newItem) 
    at System.Windows.Controls.DataGridRow.NotifyPropertyChanged(DependencyObject d, String propertyName, DependencyPropertyChangedEventArgs e, DataGridNotificationTarget target) 
    at System.Windows.Controls.DataGridRow.OnNotifyRowPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
    at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
    at System.Windows.Controls.DataGridRow.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) 
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 
    at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) 
    at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) 
    at System.Windows.Controls.DataGridRow.PrepareRow(Object item, DataGrid owningDataGrid) 
    at System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject element, Object item) 
    at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item) 
    at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container) 
    at System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32 childIndex, UIElement container, Boolean isRecycled) 
    at System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newlyRealized) 
    at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) 
    at System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.ContextLayoutManager.UpdateLayout() 
    at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg) 
    at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork() 
    at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() 
    at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) 
    at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) 
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
    at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
    at System.Windows.Threading.DispatcherOperation.InvokeImpl() 
    at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) 
    at System.Threading.ExecutionContext.runTryCode(Object userData) 
    at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Windows.Threading.DispatcherOperation.Invoke() 
    at System.Windows.Threading.Dispatcher.ProcessQueue() 
    at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
    at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
    at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) 
    at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) 
    at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) 
    at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) 
    at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) 
    at System.Windows.Application.RunDispatcher(Object ignore) 
    at System.Windows.Application.RunInternal(Window window) 
    at System.Windows.Application.Run(Window window) 
    at Oasis.App.Main() 
+0

이 문제에 대한 해결책을 찾았습니까? 이것은 나에게도 일어났습니다. 셀 템플릿 안에 MultiBinding이있는 것과 같은 상황입니다. –

+0

아니요. MultiBindings 대신 여러 개의 개별 바인딩이나 사용자 지정 속성을 사용하는 것처럼 들리지만 해결 방법이 될 수 있습니다. – xr280xr

+0

iv'e 실제로 BindingGroups에 대해 조금 읽는다고 생각합니다. Multibinding은 부모 바인딩 그룹을 실제로 상속해야하는 바인딩 그룹을 설정합니다.이 바인딩이 일부 시각화 버그라고 생각합니다. BindingGroupName = null로 설정하면이 문제를 해결할 수 있습니다. 문제는 http://msdn.microsoft.com/en-us/library/system.windows.data.bindinggroup.aspx 그리드는 개체를 얻을 때 스크롤 할 때 그리드가 BindingGroup에 추가하지 않으려 고합니다. 왜 이렇게되는지는 완전히 이해하지 못합니다.하지만이 방법을 해결할 수 있습니다. –

답변

2

실제로 작동합니까 null로 BindingGroupName 설정 여기

는 데이터 그리드 마크 업입니다. 이것은 나에게 신비한 일이며, 조금 더 잘되고있는 것을 이해하는 다른 사람이 대답을 올리면 좋겠다. 그러나, 설명서, 둘다에서 위의 게시 otzap :

당신은 FrameworkElement 또는 FrameworkContentElement에서 BindingGroup을 속성을 설정 :

http://msdn.microsoft.com/en-us/library/system.windows.data.bindinggroup.aspx

그것은 다음과 같은 말한다. 자식 요소는 다른 상속 가능한 속성과 마찬가지로 부모 요소에서 BindingGroup을 상속합니다. 다음 경우 중 하나가 발생할 경우 하위 요소에 바인딩은이 BindingGroup을 첨가한다 :

  • 바인딩의 소스와 BindingGroup을을 갖는 소자의 DataContext를가 동일한 객체와 BindingGroupName 속성이 설정되지 않은 아르 .

  • 바인딩의 BindingGroupName 속성은 BindingGroup의 Name과 같으며 명시 적으로 null로 설정되지 않습니다. 주소 예제에서 Panel의 DataContext가 Address 유형의 개체로 설정된다고 가정합니다. 각 TextBox의 바인딩이 패널의 BindingGroup에 추가됩니다.

당신이 데이터 그리드에 multibinding를 사용할 때 BindingGroup을이 바인딩의 BindingGroupName 일치하지 않는, 그래서 당신은 그 바인딩 오류가 계속 일어날 업데이트 할 때 나타납니다.

이 솔루션은 명시 적으로

<MultiBinding StringFormat="{}{0} {1}" BindingGroupName="{x:Null}"> 
     <Binding Path="FirstName"/> 
     <Binding Path="LastName" /> 
    </MultiBinding> 

처럼이 나중에 선 아래로 어떤 영향을 미칠 것인가 아무 생각하지만이 특정 예외가 멀리 갈 수 null로 MultiBinding의 BindingGroupName을 설정하는 것입니다.

관련 문제