wpf ListView GridView 上的边距/填充设置在哪里? [英] Where are the margins/padding set on a wpf ListView GridView?

查看:28
本文介绍了wpf ListView GridView 上的边距/填充设置在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 XAML 中有一个 WPF ListView/GridView 规范.第一列使用 CellTemplate 来指定图标,其他列使用 DisplayMemberBinding 来填充自己.图标栏是 20 宽,图标是 16 宽,但它们被边距/填充/某些东西截断了.我不知道它设置在哪里.

I've got a WPF ListView/GridView spec'd in XAML. The first column uses a CellTemplate to specify icons and the others use DisplayMemberBinding to populate themselves. The icons column is 20 wide, the icons 16 but they're getting truncated by margins/padding/something. I can't work out where it's set.

以下是要点(我删除了一些列,因为它们是相同的):

Here's the essentials (I've removed some columns because they're the same):

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
        <Setter Property="FontWeight" Value="Normal" />
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="FontWeight" Value="Bold" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ListView.ItemContainerStyle>

<ListView.Resources>
    <DataTemplate x:Key="image">
        <Image Width="16" Height="16" Margin="0,0,0,0"
                          HorizontalAlignment="Center"
                          Source="{Binding Path=ObjectType, 
                                           Converter={StaticResource imageConverter} }" />
    </DataTemplate>
</ListView.Resources>

<ListView.View>
    <GridView>
        <GridViewColumn Width="20"
                        CellTemplate="{StaticResource image}"/>
        <GridViewColumn Width="120" Header="Name"
                        DisplayMemberBinding="{Binding Path=Name}"/>
    </GridView>
</ListView.View>

ImageConverter 只是将 ObjectType 转换为图像,因此每种类型的项目都有自己的图标.

ImageConverter just turns an ObjectType into an image so each type of item gets its own icon.

推荐答案

使用 Snoop 找出哪个元素负责施加额外的间距.将鼠标悬停在空格上并按住 control 和 shift.然后该元素将在可视化树中突出显示.

Use Snoop to figure out which element is responsible for imposing the extra spacing. Mouse over the space and hold down control and shift. The element will then be highlighted in the visual tree.

这篇关于wpf ListView GridView 上的边距/填充设置在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆