I am building out a XamDataGrid in code. I add columns to the grid based on values in my data. I need to create bindings with converters in code so I can set the background and foregraound colors of cells.
The attached example runs and demonstrates the structure of the grid I am trying to build. However I cannot set the background / foreground color of the grid cells.
Please look in the BrokerColumnConverter class and remove the commented lines to cause the app to crash.
I am sorry for providing such a complex example however it fairly represents my project.
Note I am adding UnboundFields to the grid........ is there a way to use Field instead as I understand they are faster.
Thank you,
Sam
Hello,
Thank you for your post. I have been looking into your sample application and I would like to know, how exactly you would like to customize your XamDataGrid by applying the CellValuePresenter style.
Please attach a descriptive screenshot.
Regarding your converter, the first thing you could do is to insure that the dataitem of the current record is not null like :
if ((value[0] as DataRecord).Cells[0].Record.DataItem != null)
{
}
Looking forward to hearing from you.
Hi Yanko,
>> I would like to know, how exactly you would like to customize your XamDataGrid by applying the CellValuePresenter style.Per my original post - "I need to create bindings with converters in code so I can set the background and foregraound colors of cells."
>> the first thing you could do is to insure that the dataitem of the current record is not null like :I do not understand why the converter is called to convert nothing.... but I added the code you suggested, thanks.
My example had some bugs in it which I fixed. Will you please explain to me how I can use a Field versus unbound field to accomplish what this examaple shows?
Thank you,Sam
Thanks Yanko.
I have been looking into your latest question and the ‘Fields’ in the XamDataGrid correspond to the properties in your data source. The ‘UnboundFields’ are used to specify additional fields that are not in the underlying data source.
In your case the right approach is to use unbound field because you do not show the value of a particular property of your data source.
Let me know, if you need any further assistance on this matter.