c# - How to change background on DataGridCell depending on bound complex object value -
this want accomplish: bound collection on datagridd contain instances of rowmodel, illustrated below (minimalized simplicity), , rowmodel can contain instances of validationclass.
public class rowmodel { public int rowid { get; set; } public string column1 { get; set; } public string column2 { get; set; } public string column3 { get; set; } public icollection<validationclass> validations { get; set; } } public class validationclass { public string tag { get; set; } public string sourcecolumn { get; set; } public string errortext { get; set; } } the validationclass.sourcecolumns references columns in rowmodel has error. tag property of validationclass can either "critical" or "warning".
the validations grabbed database populated external validator. , if validation error has occured 1 or more of columns collection filled 1 validationclass per error.
now, if want set red background color on cell has critical error , yellow background on cell has warning, how can that?
datatriggers or converters, or else? need point me in right direction.
edit: clearify, i'm using c# .net4 wpf datagrid this.
triggers , converters both equaly valid problem. here solution trigger:
<datagrid.resources> <style targettype="{x:type datagridcell}"> <style.triggers> <datatrigger binding="{binding path=tag}" value="critical"> <setter property="background" value="red"/> </datatrigger> <datatrigger binding="{binding path=tag}" value="warning"> <setter property="background" value="yellow"/> </datatrigger>
Comments
Post a Comment