Is There A Way To Style A WPF DataGrid NewItem Placeholder

后端 未结 1 1308
执念已碎
执念已碎 2021-01-05 07:39

I have a simple data control defined as follows



        
相关标签:
1条回答
  • 2021-01-05 08:31

    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.

    0 讨论(0)
提交回复
热议问题