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
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.
Hi Yanko, thank you for your answer. Yes, you are correct the check inside the converter is necessary - I ommited it to demonstrate that I need a way to prevent the grid from binding until all the data is ready. I think can remove the binding from the xaml and just set it in code. No worries about that.
The second question is by far the more important one - you made a major advance using the editor style. However you will notice that the converter only changes color for each ROW. It needs to change color for each CELL. In the case of the columns that are added dynamically, the value that determines the color of the heatmap is not the Account Balance - it is the value that is computed inside the CouponColumnConverter. How do I get a reference to that value AFTER the CouponColumnConverter has run?
// At this point we can compute a value for the heat map
if (boundItem.Positions != null && boundItem.Positions.Any()) { result = boundItem.Positions.Where(x => x.Coupon == coupon).Sum(x => x.Quantity); }
if (result == 0) return Binding.DoNothing; else return result;
I am just checking if you require any further assistance on the matter.
Sorry, yes, I do need further assistance. I don't know how to add a converter from code as per my original question.
Hello,
I have been looking into your last post and I can suggest you look through the following MSDN blog where you can see how to use ValueConverter in WPF application :
http://blogs.msdn.com/b/bencon/archive/2006/05/10/594886.aspx
If you have any other questions on this matter, feel free to ask.