Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
375
XamDataGrid Custom CellValuePresenter Binding Issue
posted
Hi,
We are facing a problem when we use custom CellValuePresentor style to show an image in field's template whose visibility is bound to binded dataitem's property .
Bound item is not a concrete class instead it is a ObservableCollection of all column names and values because our columns are dynamic, we do not know how many or which columns will be there. So we have a list of columns which represent a record and then we have a list of those records which are the rows.
we are using FieldLayoutInitialized to bind to relevent dataitem and properties.
now we have bound image to DataItem which uses a converter to resolve the correct visibility value, the issue is when changing items's value by click of a button the change does not reflect on the image control immediately instead when that specific row is moved out of visible area by scrolling and then brought back to view the change then get applied.
We have made a sample project and it is attached here.
XAMGridIssue with CustomCellValueBinding.zip
  • 34690
    Verified Answer
    Offline posted

    Hello Gottfried,

    Thank you for your post.

    I have been investigating into the sample project that you have sent, and the reason that you are not seeing the image shown immediately, but you are when scrolling out of view and then back into view has to do with the binding on your converter and the virtualization of the cells in the XamDataGrid. Essentially, when cells go out of view, the CellValuePresenter that "presents" those cells is virtualized, and is therefore null. Now, you have your converter bound directly to "DataItem," and when this cell goes out of view and its presenter gets virtualized, this DataItem property no longer really exists at the scope of any of the CellValuePresenters in the grid. When you scroll the record back into view, the CellValuePresenter exists again, and so the DataItem is assigned and the converter fires, which shows your image.

    The above is the reason why you are seeing your image when scrolling away and then back to your row. The reason you are not seeing it immediately is because of the binding directly to DataItem. When you change a specific property on your DataItem, the instance of that DataItem never really changes, but the properties on it do. Since the DataItem itself isn't never actually changes, the converter never fires, and so you do not see your item.

    To resolve this, I would recommend that instead of only binding to DataItem, that you bind your Image's Visibility to a MultiBinding with an IMultiValueConverter. This will allow you to bind to multiple elements and retrieve them from your converter when the converter fires, which will be whenever one of these elements changes. I would recommend continuing to bind to DataItem for one of these bindings, as you want it in the converter, but for the other binding, I would recommend binding to the Value property of the CellValuePresenter that the image sits inside. In the case of your sample project, you will see that since the Value of your cell is changing, that this makes the converter fire, and so you will see your image immediately.

    I have attached a modified version of the sample project you had sent me to demonstrate the above. I hope this helps you.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

    TestHdadmProject.zip