gpt4 book ai didi

c# - 使用 CanUserAddRows 为 DataGrid 的新行设置样式

转载 作者:行者123 更新时间:2023-11-30 16:55:24 25 4
gpt4 key购买 nike

我需要在 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>

但是新行不是番茄颜色=( enter image description here

最佳答案

我找到了这个问题的答案!

需要.NET FrameWork 4.5

设置Trigger.Property=IsNewItemTrigger.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com