我在将 XAML 转换为代码隐藏时遇到了麻烦。
我有这个:
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding state}" Value="True">
<Setter Property="Background" Value="GreenYellow"/>
</DataTrigger>
<DataTrigger Binding="{Binding state}" Value="False">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
通过DataGrid
(伪)填充... new Dataview(ds.Tables[mytable]);
现在我正在尝试在后面的代码中创建样式和触发器,但我遇到了绑定问题。
我有
BrushConverter brushConverter = new BrushConverter();
Style setcolor = new Style();
setcolor.TargetType = typeof(DataGridRow);
DataTrigger setgreen = new DataTrigger();
setgreen.Binding = new Binding("state");
setgreen.Value = true;
setgreen.Setters.Add(new Setter(DataGrid.RowBackgroundProperty, brushConverter.ConvertFromString(Colors.GreenYellow.ToString())));
setcolor.Triggers.Add(setgreen);
-唉,它不工作