WPF:与DataGrid等效的ListViewItem

时间:2011-10-07 11:57:41

标签: wpf listview datagrid row

我有一些代码

<Style TargetType="ListViewItem">
    <Setter Property="XX" Value="true" />
</Style>

这在ListViews上按预期工作。但是,我想用DataGrid替换ListView,并且无法为Datagrid找到ListViewItem的等价物。起初我以为我期望Datagrid项继承自ListView,因此不必更改任何内容,但Setter没有任何效果。然后我改为:

<Style TargetType="DataGridRow">
    <Setter Property="XX" Value="true" />
</Style>

但它也没有效果。并且DataGridItem或DataGridViewItem不存在,所以我的选项用完了。那么,我需要什么TargetType?

1 个答案:

答案 0 :(得分:0)

您可以在DataGridRowDataGridColumnDataGridCell上设置通用样式。你使用哪一个取决于你设置的setter。

<DataGrid>
    <DataGrid.Resources>
        <Style TargetType="{x:Type DataGridCell}">
            <Setter Property="IsReadOnly" Value="True" />
        </Style>
        <Style TargetType="{x:Type DataGridRow}">
            <Setter Property="Background" Value="Green" />
        </Style>
    </DataGrid.Resources>

</DataGrid>