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,
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.
Sorry, yes, I do need further assistance. I don't know how to add a converter from code as per my original question.
Hello Sam,
I am just checking if you require any further assistance on the matter.
I have been looking into your question and if you would like to change the background of the cells according to its specific value, I can suggest you look through the following blog from our online community where Alex has provided an approach on how this can be achieved :
http://ko.infragistics.com/community/blogs/alex_fidanov/archive/2010/01/12/howto-using-wpf-converters-to-style-the-xamdatagrid.aspx
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;