画面外WPF RibbonWindow +丝带=标题? [英] WPF RibbonWindow + Ribbon = Title outside screen?

查看:471
本文介绍了画面外WPF RibbonWindow +丝带=标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在组合丝带控制 RibbonWindow ,但是他们失败了,即使在平凡的实验。

I'm trying out Ribbon control in combination with RibbonWindow, however they fail even in trivial experiments.

  1. 在创建新的 WPF应用程序
  2. 改变code到 href="http://msdn.microsoft.com/en-us/library/system.windows.controls.ribbon.ribbon.aspx">例子
  3. 添加引用 System.Windows.Controls.Ribbon 和摆脱的缎带: preFIX(为什么例子过时?)。
  4. 添加两个图标(16×16 32×32)。
  5. 执行的应用程序,看到这个(记事本,以供参考):
  1. Created new WPF Application
  2. Changed code to example from MSDN
  3. Added reference to System.Windows.Controls.Ribbon and got rid of ribbon: prefix (why are examples outdated?).
  4. Added two icons (16x16 and 32x32).
  5. Executed the application and saw this (Notepad for reference):

我已经可以看到很多问题:

I can already see numerous problems:

  1. 在边境很小。普通窗口有一个很大的边界,丝带WPF应用程序有微小的。标题高度也更小。
  2. 在边界是模糊的。当一个普通窗口的重点是,它的边框是黑色的。 WPF应用程序的边界是灰(黑可以看出,在角落;什么是绘制在边界)。
  3. 应用程序图标是错误的。它粘在左上角。
  4. 在应用程序标题是错误的。它粘在上面。

让我们将工具栏移到了底部。现在我们看到这样的:

Let's move the toolbar to the bottom. Now we see this:

按钮是工具栏外。

最后,让我们来最大化窗口:

And finally, let's maximize the window:

头的一半消失在屏幕之外(技术上窗口的的屏幕由8个像素每面的外侧,但其他应用程序不受此混淆)。

Half of the header disappeared outside of the screen (technically window is outside of the screen by 8 pixels on every side, but other apps aren't confused by this).

我使用的是Windows 7,航空,单台显示器,没什么特别的。恐怕要测试的应用程序在Windows 8 ...

I'm using Windows 7, Aero, single monitor, nothing special. I'm afraid to test the application on Windows 8...

任何机会,以解决这一问题?

Any chance to fix this?

推荐答案

引擎盖下的<一个href="http://msdn.microsoft.com/en-us/library/system.windows.shell.windowchrome.aspx"><$c$c>WindowChrome类绑定其<$​​ C $ C> ResizeBorderThickness 到 SystemParameters.WindowResizeBorderThickness 这轮流使用Win32 API <一href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385.aspx"><$c$c>GetSystemMetrics以确定系统边界尺寸

The real problem

Under the hood, the WindowChrome class binds its ResizeBorderThickness to SystemParameters.WindowResizeBorderThickness which in turns uses the Win32 API GetSystemMetrics to determine the system border size.

不过,这取决于在可执行PE文件头设置子系统版本,此方法的行为变化。如果编译仅适用于Windows Vista和更高版本(版本> = 6.0),这将返回比如果编译为旧版操作系统薄边框。 在这这方面的更多信息,以便回答。

However, the behavior of this method changes depending of the subsystem version set in the executable PE header. If compiled only for Windows Vista and later (version >= 6.0), it will return thinner borders than if compiled for older operating systems. More information on this in this SO answer.

在对.NET 4.5编译,C#编译器设置此版本6.0,因为.NET 4.5无法在XP上使用。但是, WindowChrome 类似乎依赖于传统行为,从而无法正确地计算出在Windows Vista和7的玻璃尺寸。

When compiling against .NET 4.5, the C# compiler sets this version to 6.0 since .NET 4.5 cannot be used on XP. However, the WindowChrome class seems to rely on the legacy behavior and thus fails to calculate the glass size correctly on Windows Vista and 7.

您可以编译针对.NET 4强制编译​​器使用4.0作为其子系统的版本价值。功能区可用于WPF 4为单独下载。请注意,即使有这样的解决方案,您应该取消启用在Visual Studio宿主进程中用于调试的项目属性。否则,vshost.exe过程将被使用,其被标记为6.0子系统版本

You can compile against .NET 4 to force the compiler to use 4.0 as its subsystem version value. The ribbon is available for WPF 4 as a separate download. Note that even with this solution, you should uncheck "Enable the Visual Studio hosting process" in the project properties for debugging purposes. Otherwise, the vshost.exe process will be used, which is flagged with a subsystem version of 6.0.

编辑:奥利提供一种方式来做到这一点的评论:

Olly provided a way to do this in the comments:

添加属性在项目文件   &LT; subsystemversion&GT; 5.01&LT; / subsystemversion&GT; 虚假地表示   在code可以在Windows XP上运行。

Add a property in the project file <subsystemversion>5.01</subsystemversion> that falsely indicates that the code can run on Windows XP.

您可以修改 WindowChrome.WindowChrome 连接上你的窗口属性,并使用所需的值,从而完全忽视了系统的价值。你不应该这样做,但你可以。

Ignore the system

You can change the WindowChrome.WindowChrome attached property on your window and use the values that you want, thus completely ignoring the system values. You should never do that, but you can.

上有连接关于<一个现有错误href="http://connect.microsoft.com/VisualStudio/feedback/details/753224/regression-getsystemmetrics-delivers-different-values">change在 GetSystemMetrics的行为 但是这一切都归结到子系统版本,所以它是相当从微软角度来看的功能。但是, WindowChrome 类应该被正确地固定在Vista / 7的工作,特别是因为它现在内置的.NET 4.5。

There is an existing bug on Connect about the change in behavior of GetSystemMetrics but it all comes down to the subsystem version so it's rather a feature from a Microsoft view point. However, the WindowChrome class should really be fixed to work correctly under Vista/7, especially since it's now built in .NET 4.5.

这篇关于画面外WPF RibbonWindow +丝带=标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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