ListBox margin is not the same in Windows 7 and Windows 8

二次信任 提交于 2020-01-01 08:41:55

问题


I have styled an WPF ListBox. I'm developing under Windows 8. After setup the style to be as follows (see image), when I test the application in Windows 7, the margin is not the same. As you can see in the imagen the separation between nodes is 1px in Windows 8, but 0 px in Windows 7.

Do you know why is this, and how to solve it?

Thanks in advance.


回答1:


I actually managed to get rid of it myself, it looks like it's ListViewItem style that's being changed by Windows8, adding a style to the local resources of the ListView has worked for me.

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



回答2:


You could try setting the ListBoxItem margin explicitly in a DataContext. For example:

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

Could be because Windows 7 and Windows 8 have different styles for list boxes.




回答3:


The default ListBoxItem contains a border. The ListBoxItem also specifies a padding which is inherited by this Border. Its the Padding DP that needs to be set like what Andy mentioned.



来源:https://stackoverflow.com/questions/14900132/listbox-margin-is-not-the-same-in-windows-7-and-windows-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!