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
Color XamDataGrid Cells dynamically from object property


I have a XamDataGrid that is bound to a collection of custom objects.  Each object contains a dictionary that acts as a holder for dynamic selected data.

public Dictionary<string,RowData> m_pricingData = new Dictionary<string, RowData>();

		public Dictionary<string,RowData> PricingData
			get => m_pricingData;
			set => SetProperty(ref m_pricingData, value);

		public class RowData : IOrm<RowData>
		public string Header { get; set; }

		public decimal Value { get; set; }

		public DateTime Date { get; set; }

		public int Peak { get; set; }

		public Color RowColor { get; set; }

		public RowData()

		public RowData(string header, DateTime date, decimal value, Color rowColor)
			Header = header;
			Date = date;
			Value = value;
			RowColor = rowColor;

 I have a user control with checkboxes that control which columns are added to the object's dictionary. When a checkbox is checked I generate a new field, set its binding to display a value taken from the dictionary.

			Field f = new Field()
				Name = name,
				BindingType = BindingType.UseAlternateBinding,
				AlternateBinding = new Binding($"PricingData[{name}].Value") //This binds the column to the appropriate dictionary value in the row's dynamic array of columns.
			//set field background color

The binding to display the data works correctly.

When I generate the Field, I want to set its background color dynamically based on a Color property in my RowData object that is part of the custom object's dictionary.

How can I set the color of the field based on the RowColor property of my RowData object?

No Data
  • 300
    Offline posted

    Hello Gary,

    I've been looking into your request, and I would like to ask for a clarification regarding how you would like to paint the grid.

    I understand than on an event, you add a new field(column) and set the name taken from the dictionary to be displayed in the cell value. Because the cells of this field(column) will be representing the dictionary of  every object in your collection, every cell will be holding color data.

    Do you mean you want to set the color each Cell in this field(or maybe entire Record(row)) instead? Or you just want to paint the column based on one of the colors? 

    Looking forward to your reply.

    Tihomir Tonev
    Associate Software Developer