简体   繁体   English

WPF内容与窗口边框重叠

[英]WPF contents overlaps Window border

Update 更新资料

I've confirmed that this only seems to happen on a particular PC. 我确认这似乎仅在特定PC上发生。 I think it's somehow related to my hardware setup: 我认为这与我的硬件设置有关:

  • A laptop which only has video out via USB-C 仅通过USB-C输出视频的笔记本电脑
  • A third party USB-C to HDMI adapter 第三方USB-C转HDMI适配器
  • Unbranded HDMI cable 未标记的HDMI电缆
  • An Ultrawide monitor, which I think might be pushing the limits of HDMI and/or the adapter I'm using 一个超宽显示器,我认为这可能会限制HDMI和/或我正在使用的适配器的极限

When I recently bought the adapter, I found something a little "off" with the video quality, as if it's scaling pixels despite Windows saying it's native resolution. 当我最近购买适配器时,我发现视频质量有些下降,尽管Windows表示它是本机分辨率,但好像在缩放像素。

I've read a lot about USB-C video being a little unreliable. 我已经读过很多关于USB-C视频不太可靠的信息。 I wonder whether Windows or the Laptop might get confused about the resolution when waking up from sleep. 我不知道Windows或笔记本电脑在从睡眠中醒来时是否会对分辨率感到困惑。 This might conflict with the WPF display units. 这可能与WPF显示单元冲突。


Original Question 原始问题

I must be missing something obvious, but how do I build a simple WPF window which actually fits within the Window Frame? 我必须缺少明显的东西,但是如何构建一个实际上适合窗口框架的简单WPF窗口呢?

The problem: 问题:

在此处输入图片说明

I'm using Windows 10 and Visual Studio 2015, although the same thing happens with Kaxaml. 我正在使用Windows 10和Visual Studio 2015,尽管Kaxaml也会发生相同的情况。 This XAML: 此XAML:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid> 
    </Grid>
</Window>

Results in the content, in this case a Grid, overhanging the window by a pixel or two: 导致内容(在本例中为Grid)使窗口悬空一个或两个像素:

在此处输入图片说明

How you managed to do this remains a mystery. 您如何做到这一点仍然是一个谜。 I just can't reproduce this... 我只是无法复制这个...

But I do have something you can try. 但是我有一些可以尝试的东西。

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        ClipToBounds="True">
    <Grid> 
    </Grid>
</Window>

Edit 编辑

Actually I suddenly realized this only stops the extra pixels from visually appearing. 实际上,我突然意识到这只会阻止多余的像素从视觉上出现。 This means that the Grid is still bigger than it should, and if there are contents that are rendered there, they are going to be clipped away. 这意味着Grid仍然比其应有的要大,并且如果那里渲染了内容,则它们将被裁剪掉。 But if there are nothing rendered, this should at least make this window looks normal. 但是,如果没有任何渲染,则至少应使该窗口看起来正常。

Anyway, this happening could be related to some weird windows theme that you applied or something? 无论如何,这种情况可能与您应用的某些奇怪的Windows主题有关? Some themes that made the window rendered smaller than what it should or something? 一些使窗口渲染得比其应有的东西小的主题?

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

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