Hi ,
I need to dynamically create and apply cell style selector to a perticualr column. Can you help me with this?
I need to dynamically create and apply cell style selector to a perticualr column. Can you help me with this?
void ViewModel_delApplyRuleEvent()
{
Dictionary<
string
, ColorRuleConfig> dictColorRuleConfig = viewmodelobj.dictColorRuleConfig;
if (dictColorRuleConfig != null && dictColorRuleConfig.Count > 0)
{
foreach (var item in dictColorRuleConfig)
{
GridViewColumn col = dataGrid1.Columns[item.Value.ColumnName];
Color backcolor = new Color();
backcolor.A = 255;
backcolor.R = byte.Parse(item.Value.RuleBackColor.Substring(0, 2), NumberStyles.HexNumber);
backcolor.G = byte.Parse(item.Value.RuleBackColor.Substring(2, 2), NumberStyles.HexNumber);
backcolor.B = byte.Parse(item.Value.RuleBackColor.Substring(4, 2), NumberStyles.HexNumber);
SolidColorBrush BrushBackColor = new SolidColorBrush(backcolor);
Color forecolor = new Color();
forecolor.A = 255;
forecolor.R = byte.Parse(item.Value.RuleForeColor.Substring(0, 2), NumberStyles.HexNumber);
forecolor.G = byte.Parse(item.Value.RuleForeColor.Substring(2, 2), NumberStyles.HexNumber);
forecolor.B = byte.Parse(item.Value.RuleForeColor.Substring(4, 2), NumberStyles.HexNumber);
SolidColorBrush BrushForeColor = new SolidColorBrush(forecolor);
string[] strarr = item.Value.RuleExpression.Split(new char[] { '=' });
string strColName = strarr[0];
string strColVal = strarr[1];
Tuple<
SolidColorBrush
, SolidColorBrush> ColorsProperty = Tuple.Create<
SolidColorBrush
, SolidColorBrush>(BrushBackColor, BrushForeColor);
Func<
string
, bool> FuncProperty= (s) => { if (s == strColVal) return true; return false; };
Style st = new Style(typeof(GridViewCell));
st.Setters.Add(new Setter(GridViewCell.BackgroundProperty, ColorsProperty.Item1));
st.Setters.Add(new Setter(GridViewCell.ForegroundProperty, ColorsProperty.Item2));
this.Resources.Add(item.Value.ColumnName + "CellStyle", st);
//***********************i am stuck up here******************************************
StyleSelector sc = new StyleSelector();
sc.SelectStyle(dataGrid1.Columns[item.Value.ColumnName],
dataGrid1.Columns[item.Value.ColumnName].CellStyleSelector = sc;
}
}
}