When data is bound to a grid, how can I change the color of a label, programmatically, when a value is negative?
Perfect. Thank you!
Hello PMac,
In the case that you are Auto-Generating the Fields in the XamDataGrid, I would recommend that you obtain the desired Field and place your CellValuePresenter style on that Field's FieldSettings.CellValuePresenterStyle property programmatically.
You can do this by giving the Style for CellValuePresenter an x:Key. Then, you can get it by using the following code, where "owningElement" is the <Element>.Resources that you have placed the style in:
Style style = owningElement.Resources["myKey"] as Style;
Once you obtain this, you can utilize either the Loaded or FieldLayoutInitialized event of the XamDataGrid to get the Field that you are looking to set the CellValuePresenter style on, and set it. You can use the following sample code for this, where "xdg1" is the XamDataGrid:
//In the Loaded event for the XamDataGrid...Field field = xdg1.FieldLayouts[0].Fields["myField"];field.Settings.CellValuePresenterStyle = style;
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Sorry, type-o.... I meant to say where AutoGenerateFields = "True"... which is the case I am testing
The sample project is also using XamDataGrid.FieldLayoutSettings.AutoGenerateFields = "False." I'm unsure why this necessitates setting your colors programmatically, though?
You are correct that the CellValuePresenterStyle property did not exist directly on the Field in 14.1. In that version, this property existed on the FieldSettings element which can be used for the Settings property of each Field. You can set the CellValuePresenterStyle property in XAML like so in 14.1:
<ig:Field><ig:Field.Settings><ig:FieldSettings CellValuePresenterStyle="{StaticResource style}" /></ig:Field.Settings></ig:Field>
Thank you for your help. I am using Autotgenerated="False", hence why I was thinking of doing this programmatically.
I'll attempt the Style approach.... although I'm on V14.1 and do not see CellValuePresenterStyle attribute available for Field tags.