Welcome to the Xceed Community | Help
Community Search  
More Search Options

DataCell.DataContext on MultiBinding on IMultiValueConverter becomes out of sync if AutoFilter used

Sort Posts: Previous Next
  •  03-11-2010, 8:37 PM Post no. 26083

    Lightning [li] DataCell.DataContext on MultiBinding on IMultiValueConverter becomes out of sync if AutoFilter used

    This is a new issue pertaining to other related issues raised:

    If I have an IMultiValueConverter assigned to a MultiBinding on a DataCell Style.Setter, with a Binding to the DataCell itself and/or its Content property and another Binding to its DataContext property, if the converter is then invoked by changing the AutoFilterValues on one of the columns in the grid, after several calls to the converter, the bindings become out of sync and start pointing to completely different objects when they should in fact always be related to the same DataCell.

    I've attached an example project demonstrating this error.  To reproduce it, follow these steps:

    1. Run the application in the debugger.

    2. Once the grid and all its value have been displayed, put the following entries in the Watch window:

        ((System.Data.DataRowView)(((System.Windows.FrameworkElement)(cell)).DataContext)).Row.ItemArray

        row.ItemArray

    3. Put a breakpoint at line 72 of Page1.xaml.cs:

       if (!content.Equals(row.Table.Rows[currentRowIndex-1][cell.FieldName]))

    4. Select one of the AutoFilter values from any column (e.g., 'MyProp1' column)

    5. At the breakpoint, expand the arrays for the two entries in the Watch window.  They should be identical.

    6. Press F5 to cycle through each DataCell stopping at the breakpoint for each DataCell and keep an eye on the values of the two arrays in the Watch window.

     

    Keep cycling through and you will notice after several iterations, the values in the arrays become out of sync.  They are no longer identical.  This is not supposed to happen because they represent the DataContext via the binding to the DataCell and the DataContext via the binding to the DataCell.DataContext property directly of the same DataCell as the first binding.

    This seems to be a bug and it means I cannot use your MultiBinding solution for a grid where I need to use filtering.  Please could you look into this?

    Thanks,

    Jason


    Associate, .NET Development
    Morgan Stanley, UK
  •  03-16-2010, 4:40 PM Post no. 26139 in reply to 26083

    Re: DataCell.DataContext on MultiBinding on IMultiValueConverter becomes out of sync if AutoFilter used

    Hi Jason,

    We can't confirm for sure why exactly this is happening. However it may have to do with how the multibinding converter will be called for each modification of the binding he is composed of. Therefore it's possible that you got one call after the content changed but the context was not yet considered refreshed when the converter has been called and during that call you have a different value for the context.

     


    Diane Lafontaine
    Technical Support / Technical Support Team Lead
    Xceed Software Inc.
  •  03-16-2010, 4:42 PM Post no. 26140 in reply to 26139

    Re: DataCell.DataContext on MultiBinding on IMultiValueConverter becomes out of sync if AutoFilter used

    OK, so, is this a bug with the way the MultiBinding is working with the grid?  If so, can it be fixed?  What's the work-around?
    Associate, .NET Development
    Morgan Stanley, UK
  •  03-16-2010, 5:30 PM Post no. 26141 in reply to 26140

    Re: DataCell.DataContext on MultiBinding on IMultiValueConverter becomes out of sync if AutoFilter used

    Hi Jason,

    It's the way multibinding works that indirectly causes the issue. But if you base your conversion on the parameter received, everything should be fine because the converter will be called more than one time, and the last time he will be called for a given Cell, should be with the correct value.

     


    Diane Lafontaine
    Technical Support / Technical Support Team Lead
    Xceed Software Inc.
  •  03-19-2010, 8:10 AM Post no. 26199 in reply to 26141

    Re: DataCell.DataContext on MultiBinding on IMultiValueConverter becomes out of sync if AutoFilter used

    OK, that makes sense.  It causes problems when the converter code checks if this DataContext value != null and because of this assumes that Cell.ParentRow.Cells["MyField"].Content is also != null.  This pitfall should probably be documented.

    I've refactored my code to not make this assumption and now even use Cell.ParentRow at all now, but rather the ((DataRowView)DataContext).Row["MyField"] instead.

    Thanks for your help.

    Jason


    Associate, .NET Development
    Morgan Stanley, UK
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.