我有这种风格:
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
如何获取更改背景的行。