2013-02-15 71 views
10

我已经设计了一个WPF列表框。我在Windows 8下开发。设置样式如下(见图),当我在Windows 7中测试应用程序时,边距不一样。正如你可以在imagen画质节点之间的分离是1px的在Windows 8中看到的,但0 PX在Windows 7列表框边距在Windows 7和Windows 8是不一样的

enter image description here

你知道这是为什么,以及如何解决呢?

在此先感谢。

+1

您是否尝试过使用snoop(http://snoopwpf.codeplex.com/)查看W7列表框是否正在考虑您正在设置的边框? – 2013-02-15 18:32:47

+0

我有同样的问题,额外的保证金空间不会出现在窥探中。 – Andy 2013-03-25 14:48:17

回答

6

我实际上设法摆脱它自己,它看起来像是由Windows8更改的ListViewItem样式,添加样式到ListView的本地资源已为我工作。

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

这很好。似乎只有填充和BorderThickness才能解决它。 – 2014-05-02 03:00:40

-1

您可以尝试在DataContext中显式设置ListBoxItem边距。 例如:

<ListBox> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock Text="{Binding}" Margin="0,0,0,1" /> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

可能是因为Windows 7和Windows 8对列表框不同的风格。

+0

设置边距实际上并没有为我解决这个问题,看起来这是在列表项周围出现的额外边距。 – Andy 2013-03-25 15:33:18

+0

尝试设置填充值和边框厚度值。您可以使用[snoop](http://snoopwpf.codeplex.com/)查看正在设置的值。 – 2013-03-27 17:02:59

-1

默认的ListBoxItem包含边框。 ListBoxItem还指定由此边框继承的填充。它的填充DP需要像安迪提到的那样设置。