首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF DataGridCell裕度

WPF DataGridCell裕度
EN

Stack Overflow用户
提问于 2014-09-24 16:35:34
回答 1查看 6.4K关注 0票数 2

我有以下数据网格:

代码语言:javascript
复制
<DataGrid Name="PropertiesDataGrid" 
          ItemsSource="{Binding PropertiesDataView, UpdateSourceTrigger=PropertyChanged}"
          SelectedItem="{Binding SelectedProperty, Mode=TwoWay, 
                       UpdateSourceTrigger=PropertyChanged}"
          AutoGenerateColumns="False"
          CanUserAddRows="False"
          MaxHeight="200">
    <i:Interaction.Behaviors>
        <helper:ScrollIntoViewBehavior/>
    </i:Interaction.Behaviors>

    <DataGrid.Columns>
        <DataGridTemplateColumn Header="">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Button Command="Delete"
                            Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
                        <Image Source="../Resources/red_x.ico" 
                               Height="15" />
                    </Button>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>

        <DataGridTextColumn Header="ID"
                            Width="50" 
                            Binding="{Binding ID}" 
                            ElementStyle="{StaticResource CenterTextCellStyle}" 
                            IsReadOnly="True" />

        <DataGridTextColumn Header="PropertyName"
                            Width="*" 
                            Binding="{Binding PropertyName}" 
                            ElementStyle="{StaticResource LeftTextCellStyle}" />

        <DataGridTextColumn Header="PropertyValue" 
                            Width="300" 
                            Binding="{Binding PropertyValue}" 
                            ElementStyle="{StaticResource LeftTextCellStyle}" />
    </DataGrid.Columns>

</DataGrid>

应用于此数据网格的样式如下:

代码语言:javascript
复制
<Style TargetType="{x:Type DataGridCell}">
    <Setter Property="Height" Value="22" />
    <Setter Property="Margin" Value="5,0,0,0" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridCell}">
                <Grid Background="{TemplateBinding Background}">
                    <ContentPresenter VerticalAlignment="Center" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

此样式将5像素的间距添加到单元格内容的左侧,并将文本垂直居中。

我想将第一列的单元格(<DataGridTemplateColumn Header="">)的边距设置为0。我如何在DataTemplate中设置它。我知道必须在DataGridCell上设置边距(通过使用Snoops找到),但不知道如何在<DataGridTemplateColumn.CellTemplate>中实现

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-24 17:12:11

层叠风格:

代码语言:javascript
复制
<DataGridTemplateColumn Header="">
    <DataGridTemplateColumn.CellStyle>
        <Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource {x:Type DataGridCell}}">
            <Setter Property="Margin" Value="0" />
        </Style>
    </DataGridTemplateColumn.CellStyle>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26022106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档