Is there a way to style WPF DataGrid NewItem Placeholder

I have a simple data control, which is 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> 

I specified CanUserAddRows = "True". As announced, this places an empty row at the bottom of the grid so the user can add a new row.

Is there a way to erase this new replacement element regardless of the rest of the grid?

+7
wpf xaml wpfdatagrid
source share
1 answer

Yes, you can change this placeholder string.

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> 

This placeholder line will appear with a yellow background.

+8
source share

All Articles