简体   繁体   English

WPF Dock Panel 奇怪的魔术师

[英]WPF Dock Panel wierd magin

I have a very simple dockpanel inside a border.我在边框内有一个非常简单的停靠面板。 But the dock panel seems to have a 1px margin on the right and bottom.但是停靠面板的右侧和底部似乎有 1px 的边距。 I cant seem to get rid of it by setting the margin or the dockpanel nor by setting the padding of the border.我似乎无法通过设置边距或停靠面板或设置边框的填充来摆脱它。

What exactly is causing it and how can I fix it without hacking it (IE negative margin on the dock panel)究竟是什么导致了它以及如何在不破解它的情况下修复它(即停靠面板上的负边距)

<Window x:Class="WPFTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Height="350" Width="525">
    <Grid>
        <Border BorderBrush="Black" BorderThickness="2" Padding="0">
            <DockPanel Background="Blue" Margin="0"/>
        </Border>
    </Grid>
</Window>

在此处输入图片说明

No style defined on Border or DockPanel. Border 或 DockPanel 上没有定义样式。 Tried this on a brand new project and still seeing the white lines在一个全新的项目上尝试了这个,仍然看到白线

The usual way you get gaps like that in XAML is becasue the UI is being scaled.在 XAML 中出现这种差距的通常方式是因为 UI 正在被缩放。 If you can't find anything that might be scaling it ( RenderTransform in a parent, OS settings such as font size, probably other stuff), you could try playing with UseLayoutRounding and SnapsToDevicePixels .如果您找不到任何可能对其进行缩放的内容(父项中的RenderTransform 、字体大小等操作系统设置,可能还有其他内容),您可以尝试使用UseLayoutRoundingSnapsToDevicePixels

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM