Dot-Net

Windows 7 和 Windows 8 中的 ListBox 邊距不同

  • April 1, 2013

我已經設計了一個 WPF 列錶框。我在 Windows 8 下開發。將樣式設置為如下(見圖)後,當我在 Windows 7 中測試應用程序時,邊距不一樣。正如您在圖像中看到的,節點之間的間隔在 Windows 8 中為 1px,但在 Windows 7 中為 0 px。

在此處輸入圖像描述

你知道這是為什麼,以及如何解決嗎?

提前致謝。

實際上我自己設法擺脫了它,看起來它的 ListViewItem 樣式正在被 Windows8 更改,向 ListView 的本地資源添加樣式對我有用。

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

預設的 ListBoxItem 包含一個邊框。ListBoxItem 還指定了一個由此邊框繼承的填充。它的 Padding DP 需要像 Andy 提到的那樣設置。

引用自:https://stackoverflow.com/questions/14900132