WPFToolkit DataGrid在setter(样式)中设置单元格的值

时间:2012-03-01 21:57:16

标签: wpf datagrid

我有DataGrid,我设置:

CellStyle="{StaticResource Style}"

我的风格:

<Style x:Key="Style" TargetType="{x:Type tool:DataGridCell}" >
    <Setter Property="Content" Value="QWE" />
</Style>

但细胞没有“qwe”文字。

1 个答案:

答案 0 :(得分:1)

设置Template,然后设置Content的{​​{1}} ...

ContentPresenter

然后您可以添加项目,内容将显示为 qwe

       <Style x:Key="CenterCellStyle" TargetType="{x:Type tool:DataGridCell}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type tool:DataGridCell}">
                        <Grid Background="{TemplateBinding Background}">
                            <ContentPresenter Content="qwe"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>