有没有一种样式WPF DataGrid NewItem占位符的样式 [英] Is There A Way To Style A WPF DataGrid NewItem Placeholder
本文介绍了有没有一种样式WPF DataGrid NewItem占位符的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个定义如下的简单数据控件
I have a simple data control defined as follows
<DataGrid x:Name="ScheduleDataGrid" AutoGenerateColumns="False" CanUserAddRows="True" CanUserDeleteRows="True" Margin="5" ItemsSource="{Binding ScheduleItems}">
<DataGrid.Columns>
<DataGridTextColumn...></DataGridTextColumn>
....
<DataGridTextColumn...></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
我指定了CanUserAddRows = True。如广告所示,这会在网格底部放置一个空白行,供用户添加新行。
I have specified CanUserAddRows="True". As advertised, this puts a blank row at the bottom of the grid for the user to add a new row.
有没有一种方法可以独立于新项目占位符的样式
Is there a way to style that new item placeholder independently of the rest of the grid?
推荐答案
是的,可以更改该占位符行。
Yes it is possible to change that placeholder row.
看看我刚才做的这个例子。
Take a look at this example I just made.
<Window.Resources>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<DataTrigger Binding="{Binding}" Value="{x:Static CollectionView.NewItemPlaceholder}">
<Setter Property="Background" Value="Yellow"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<DataGrid AutoGenerateColumns="False" CanUserAddRows="True" ItemsSource="{Binding List}">
<DataGrid.Columns>
<DataGridTextColumn Header="Test" Binding="{Binding Path=Name, Mode=TwoWay}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
该占位符行将显示为黄色背景。
That placeholder row will appear with yellow background.
这篇关于有没有一种样式WPF DataGrid NewItem占位符的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文