如果值大于,XAML Datagrid 设置 rowStyle
我有一个带有3列的数据杂志。
现在,我想有条件地更改行的亮点。 类似:如果第2列中的值大于xx将行颜色更改为红色。
我已经尝试了一些事情,但是没有成功:
<DataGrid Name="DataGrid1" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3" AlternatingRowBackground="LightGray" ItemsSource="{Binding}" AutoGenerateColumns="False" FontSize="18" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserAddRows="False">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Steckzyklen}" Value="< 20">
<Setter Property="Background" Value="#FFFF4848"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Steckplatz" Binding="{Binding Name}" Width="200"/>
<DataGridTextColumn Header="Steckzyklen" Binding="{Binding Steckzyklen}" Width="200"/>
<DataGridTextColumn Header="Austauschdatum" Binding="{Binding Austauschdatum}" Width="200"/>
</DataGrid.Columns>
</DataGrid>
在这一行中:dataTrigger binding =“ {binding steckzyklen}” value =“&amp; lt 20” 我尝试用&amp; lt做这件事,但没有成功。
有人知道如何使它起作用?最好仅通过更改XAML中的内容。
提前致谢!
I've got a Datagrid with 3 columns.
Now i want to change the highlight of the row conditionally.
like: if the value in column 2 is greater than XX change row color to Red.
I've already tried something, but without success:
<DataGrid Name="DataGrid1" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3" AlternatingRowBackground="LightGray" ItemsSource="{Binding}" AutoGenerateColumns="False" FontSize="18" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserAddRows="False">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Steckzyklen}" Value="< 20">
<Setter Property="Background" Value="#FFFF4848"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Steckplatz" Binding="{Binding Name}" Width="200"/>
<DataGridTextColumn Header="Steckzyklen" Binding="{Binding Steckzyklen}" Width="200"/>
<DataGridTextColumn Header="Austauschdatum" Binding="{Binding Austauschdatum}" Width="200"/>
</DataGrid.Columns>
</DataGrid>
In this line: DataTrigger Binding="{Binding Steckzyklen}" Value="< 20"
I tried ti do it with the < but without succes.
Someone knows how to make it work? Preferably by only changing something in the XAML.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以按以下方式更改样式:
创建一个新的转换器:
然后:
You can change the Style as follows:
Create a new Converter:
And then: