我需要在 DataGrid
中为 CanUserAddRows
设置一个行的样式。
ItemsSource
用于 DataGrid
我使用 DataTable.DefaultView
我试试:
<DataGrid IsReadOnly="false" CanUserAddRows="True">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource {x:Type DataGridCell}}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=.}" Value="{x:Null}">
<Setter Property="Background" Value="Tomato"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Width="*" Binding='{Binding Path=Col1}' Header="Col1" />
<DataGridTextColumn Width="*" Binding='{Binding Path=Col2}' Header="Col2" />
<!-- more columns -->
</DataGrid.Columns>
</DataGrid>
但是新行不是番茄颜色=(
最佳答案
我找到了这个问题的答案!
需要.NET FrameWork 4.5
设置Trigger.Property=IsNewItem 和Trigger.Value=true:
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource {x:Type DataGridRow}}">
<Style.Triggers>
<Trigger Property="DataGridRow.IsNewItem" Value="true">
<Setter Property="DataGridCell.Background" Value="Tomato"/>
</Trigger>
</Style.Triggers>
</Style>
关于c# - 使用 CanUserAddRows 为 DataGrid 的新行设置样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29530608/