Xaml Windows8列表视图和项目之间的间距

Xaml Windows8列表视图和项目之间的间距,xaml,listview,gridview,windows-8,windows-store-apps,Xaml,Listview,Gridview,Windows 8,Windows Store Apps,我想更改listView中项目之间的间距(也许我应该使用另一个视图元素?)代码如下所示: <ListView SelectionMode="None" HorizontalContentAlignment="Left" > <ListView.Items> <TextBlock Text="Item 1" /> <TextBlock Text="Item 2" />

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

    <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(WCH可以包装元素)。目前项目之间的空间(水平空间)太大。我的上一个问题->


提前感谢

您需要编辑ListBox.ItemContainerTemplate属性。Blend或VS visual designer有助于将其提取以进行修改。

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


嘿
嘿
要获得更多控件,请通过在设计器中选择listviewitem并右键单击来复制整个默认模板。选择编辑模板,编辑副本。这将生成默认模板,您可以在那里进行更改。您可以对listviewcontainer执行相同的操作。也可以通过使用“混合”来实现这一点

让我知道进展如何,如果你有更多的问题!祝你好运

编辑:

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

据我所知(windows8.1 xaml应用商店),在将这两个设置为零后

<ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="Padding" Value="0"/>
                    <Setter Property="Margin" Value="0"/>

我仍然有令人沮丧的差距,我似乎无法摆脱

在此处使用负边距可能会对您有所帮助,但。。。它很老套,很难处理,并且不会总是带来预期的结果

在把我的头发拔出来后,我发现这个问题已经解决了

ContentMargin=“0”Padding=“0”

在ListViewItemPresenter中,如下所示:

        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="Padding" Value="0" />
                <Setter Property="Margin" Value="0" />
                <Setter Property="BorderThickness" Value="0" />
                <Setter Property="VerticalContentAlignment" Value="Top" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListViewItem">
                            <ListViewItemPresenter ContentMargin="0" Padding="0" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ListView.ItemContainerStyle>


希望这样可以避免其他人在键盘上反复砸脑袋;)

用于删除Windows 8.1应用商店应用程序GridView项目中的边距的解决方案。受上述ListView解决方案的启发

<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="GridViewItem">
                <GridViewItemPresenter ContentMargin="0" Padding="0"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
</GridView.ItemContainerStyle>


我认为这里要修改的正确ItemContainerStyle属性是MinHeight,而不是边距或填充。

谢谢帮助:)还有一个问题。我几乎可以肯定应该用他的方式来做,但我找不到任何可以编辑这些样式的工具。例如,我如何在Blend中做到这一点?我已经发布了一篇博文,其中包括了如何在VS或Blend中做到这一点的描述和图片:)希望能有所帮助!不要犹豫问更多的问题。链接:哇,太棒了!非常感谢:)NP,很高兴能够提供帮助:)玩得开心:)我必须这么做才能让它为我工作……是的,特别是,在它里面ListViewItemPresenter的内容边距和填充属性你救了我一天,伙计:-):-)。我已经花了好几个小时在这上面了,如果我没有找到的话,我会花上好几天的时间!我仍然需要一个负的ContentMargin来进一步降低利润率!经过一系列的尝试和错误后,这对我来说非常有效。哇,它不仅在最初的目的下非常有效,而且在窗口大小减小时也非常有效:以前,一些底部列表项被剪裁,而现在,它没有!
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="GridViewItem">
                <GridViewItemPresenter ContentMargin="0" Padding="0"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
</GridView.ItemContainerStyle>