首页 > 解决方案 > Button Border clipped in WPF with 125% DPI Setting

问题描述

When I use 125% DPI setting in Windows, sometimes a button border is not rendered. It seems to depend on the size and position, maybe also the parent element of a button:

enter image description here

In my app, I can also see in the WPF designer that a parent border seems to be too small in size, though the button itself is larger. Maybe the measure process is somehow wrong:

enter image description here

I tried changing UseLayoutRounding for the whole window, also changing SnapsToDevicePixels does not help. DPI Awareness is set in the manifest.

Does anyone know how to fix this for the entire application?

Thats the code in a default Wpf Window Application (I can't reproduce the problem right now, but the problem persists in my application):

<Window x:Class="WpfApp3.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"
        Title="MainWindow"
        SizeToContent="WidthAndHeight">

    <StackPanel>
        <GroupBox>
            <GroupBox.Header>
                <Button Width="20"
                        Height="22"
                        Content="X" />
            </GroupBox.Header>
        </GroupBox>

        <Button Width="20"
                Height="22"
                VerticalAlignment="Center"
                HorizontalAlignment="Left"
                Content="X" />
    </StackPanel>
</Window>

标签: wpfdpigroupboxhighdpi

解决方案


推荐阅读