我有这种风格:
private Style ColorStyle(Container.ColorTrigger trigger)
{
Style style = new Style();
style.TargetType = typeof(DataGridRow);
DataTrigger dtGreen = new DataTrigger();
bool triggervalue = Convert.ToBoolean(trigger.Trigger);
IValueConverter converter = AssignConverter(trigger.Operator);
dtGreen.Binding = new Binding(trigger.Binding) { Converter = converter, ConverterParameter = trigger.Value };
dtGreen.Value = !triggervalue;
dtGreen.Setters.Add(new Setter(Control.BackgroundProperty, Brushes.LawnGreen));
DataTrigger dtRed = new DataTrigger();
dtRed.Binding = new Binding(trigger.Binding) { Converter = converter, ConverterParameter = trigger.Value };
dtRed.Value = triggervalue;
dtRed.Setters.Add(new Setter(Control.BackgroundProperty, Brushes.Red));
style.Triggers.Add(dtGreen);
style.Triggers.Add(dtRed);
return style;
}
样式设置在DataGrid
。
当触发器将Brushes.Red
设置为BackgroundProperty
时,如何调用方法?如何获取背景更改的行。
答案 0 :(得分:0)
在Binding中附加TargetUpdated处理程序。
http://msdn.microsoft.com/en-us/library/system.windows.data.binding.targetupdated.aspx