Windows8 ListView和项目之间的空间 [英] Windows8 ListView and space between items

查看:23
本文介绍了Windows8 ListView和项目之间的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改 listView 中项目之间的间距(也许我应该使用另一个视图元素?)代码如下所示:

I want to change spacing between items in listView (maybe i should use another View-element?) Code looks like this:

    <ListView SelectionMode="None" HorizontalContentAlignment="Left" >
        <ListView.Items>
            <TextBlock Text="Item 1" />
            <TextBlock Text="Item 2" />
            <TextBlock Text="Item 3" />
            <TextBlock Text="Item 4" />
        </ListView.Items>
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapGrid Orientation="Horizontal" HorizontalChildrenAlignment="left"/>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
    </ListView>

我想尽可能地模仿普通的stackpanel(可以包装元素).目前,物品之间的空间(水平空间)太大了.我之前的问题 -> Windows 8 WrapPanel

I want to imitate as much as possible normal stackpanel (wchich can wrap elements). Currently spaces (horizontal space) beetween items are far too big. My previous question -> Windows 8 WrapPanel

提前致谢

推荐答案

您需要对默认模板进行更改.如果您只想进行简单的更改,例如填充和边距,那么您可以这样做:(测试代码并且应该可以工作)

You will need to make changes to the default template. If you just want to make simple changes such as the padding and margins then you can do this: (tested the code and should work)

            <ListView>
        <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapGrid Orientation="Horizontal" HorizontalChildrenAlignment="left"/>
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
        <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="Padding" Value="0"/>
                    <Setter Property="Margin" Value="0"/>
                </Style>
            </ListView.ItemContainerStyle>
            <ListViewItem>
                <TextBlock Foreground="Wheat">hej</TextBlock>
            </ListViewItem>
            <ListViewItem>
                <TextBlock Foreground="Wheat">hej</TextBlock>
            </ListViewItem>
        </ListView>

要获得更多控制权,请通过在设计器中选择一个列表视图项并右键单击来复制整个默认模板.选择编辑模板,编辑副本.这将生成默认模板,您可以在那里进行更改.您可以对 listviewcontainer 执行相同的操作.您也可以使用 Blend 来做到这一点.

For more control make a copy of the whole default template by selecting a listviewitem in the designer and rightclicking. select edit template, edit copy. This will generate the default template and you can make your changes there. You can do the same for the listviewcontainer. You can also do this by using Blend.

我在这里添加了描述和图片(如何编辑默认模板)

如果您还有其他问题,请告诉我进展如何!祝你好运!

Let me know how it goes, and if you have more questions! Good luck!

MemeDeveloper 在下面提到他仍然有问题,并通过调整其他一些属性来解决 - 他在此处发布了代码和答案,请务必查看.

MemeDeveloper mentioned below that he still had issues and solved it by tweaking some other properties- he posted a code and answer here, make sure to take a look.

这篇关于Windows8 ListView和项目之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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