简体   繁体   中英

WPF contents overlaps Window border

Update

I've confirmed that this only seems to happen on a particular PC. I think it's somehow related to my hardware setup:

  • A laptop which only has video out via USB-C
  • A third party USB-C to HDMI adapter
  • Unbranded HDMI cable
  • An Ultrawide monitor, which I think might be pushing the limits of HDMI and/or the adapter I'm using

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.

I've read a lot about USB-C video being a little unreliable. I wonder whether Windows or the Laptop might get confused about the resolution when waking up from sleep. This might conflict with the WPF display units.


Original Question

I must be missing something obvious, but how do I build a simple WPF window which actually fits within the Window Frame?

The problem:

在此处输入图片说明

I'm using Windows 10 and Visual Studio 2015, although the same thing happens with Kaxaml. This 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:

在此处输入图片说明

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. 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? Some themes that made the window rendered smaller than what it should or something?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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