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
3160
How to add a converter to a dynamically added column
posted

The attached example shows two XamDataGrids.
The first grid works (with exceptions noted below) and serves to illustrate what I want to accomplish with the second grid.

Note that the second data grid handles the FieldLayoutInitialized event and adds columns on the fly.
When a column is added, a multibinding is added to the field definition. 
The multibinding specifies a converter (CouponColumnConverter) that allows the field to calculate its value.

I have two questions related to this code:
1.) When the refresh button is clicked the Accounts list is re-populated with new data.
Before the grid can bind, MinAccountBalance and MaxAccountBalance must be computed however the grid attempts to bind too early causing the heatMap converter to crash.
How do I prevent the grid from binding?

2.) I need to implement the HeatMap converter for each column that is added to the second grid.  How do I  do that?

Thanks,

Sam
 

HeatMapProblem.zip
  • 35319
    posted

    Hello Sam,

     

    I have been looking into your issue and it seems that when you change the ‘DataSource’ of your XamDataGrids, its new data makes the ‘val’ variable to be more than 1 or less than 0. This makes the ‘R’ and ‘G’ parameters of the Color class to have irrelevant values which makes your application crashes. I can suggest you make a check as :

     

      if (val > 1) val = 1;

      if (val < 0) val = 0;

     

    in the converter’s body.

     

    According to your second question I can suggest defining the Style for the XamTextEditor in the Resources of the Window and after that setting this style as a ‘EditorStyle’ for the second XamDataGrid.

     

    I am attaching a modified version of your sample application(HeatMapProblemModified.zip) following my suggestions.

     

    If you need any further assistance on this matter, feel free to ask.

    HeatMapProblemModified.zip