WPF无边框窗口不同分辨率下的最大化问题 [英] WPF Borderless window Maximized issue on different resolutions

查看:30
本文介绍了WPF无边框窗口不同分辨率下的最大化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WPF 中有无边框窗口,它使用了一些自定义样式.我正在使用具有不同分辨率的多台显示器来显示应用程序.当应用程序从较小的分辨率移动到最大的分辨率监视器时,应用程序未正确最大化并且屏幕的某些区域显示为空.我怎样才能让它在所有分辨率下都最大化?

I have borderless window in WPF which is using some custom styles. I am using the multiple monitors with different resolutions to show the application. When application moves from smaller resolution to biggeest resolution monitor the application is not properly maximized and some area of the screen show empty. how can i make it maximized on all the resolutions?

谢谢

推荐答案

尝试使用 WindowChrome 类绘制窗口.此功能允许重绘窗口的非客户区.这意味着您可以将无边框窗口用作 SingleBordered 窗口.它解决了自定义窗口的许多问题.如果您的目标是 .NET 4.5,只需输入:

Try using WindowChrome class to draw window. This feature allows to redraw non-client area of a window. This mean You can have borderless window acting as SingleBordered one. It resolve a lot of problems with custom windows. If You target .NET 4.5, just type:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">

<WindowChrome.WindowChrome>
    <WindowChrome/>
</WindowChrome.WindowChrome>

<Grid>

</Grid>
</Window>

对于低于 4.5 的 .NET 您必须引用 Microsoft.Windows.Shell.dll 然后使用例如shell:WindowChrome 获得相同的结果.

For .NET below 4.5 You have to reference Microsoft.Windows.Shell.dll and then use e.g. shell:WindowChrome for the same results.

也不要使用

WindowState = Windows.WindowState.Maximized

改为输入例如

<Button x:Name="buttonMaximize" Command="{Binding Source={x:Static SystemCommands.MaximizeWindowCommand}}">

使用默认的 Windows 操作来最大化窗口并带有动画和完美缩放.

which use default Windows action to maximize window with animation and perfect scaling.

这篇关于WPF无边框窗口不同分辨率下的最大化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆