WPF:Windows 7 与 Windows 10 外观对比 [英] WPF: Windows 7 vs Windows 10 Appearance

查看:33
本文介绍了WPF:Windows 7 与 Windows 10 外观对比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 10 设备和 Windows 7 设备之间有恼人的外观差异.

我在 Window 元素中直接使用 WindowStyle="None"DockPanel.

我不明白的是为什么还有边界?为什么按钮、文本框、组合框等的边框是圆角的?

这似乎与Aero有关.有什么方法可以阻止我的应用程序使用 Aero?我假设还有另一个与 Windows 10 相关的演示框架,但不知道强制使用它的名称是什么.

BorderBrush 会是解决这个问题的最简单方法吗?

<DockPanel x:Name="Root_Window" Background="Black"><!--应用程序在这里--></DockPanel></窗口>

Windows 7 显示:

Windows 10 显示:

一切仍然正常,但某些文本框和按钮的设置方式,缺少部分字母.

解决方案

我认为很多人在真正开始自定义应用程序的样式时都会偶然发现这两种情况.这两个问题都有一些完善的快捷方式,例如使用 WPF 的现有样式/库:

我看到了一些常见的 Window 和样式库:

  • MahApps.Metro 是一个很棒的库,我用了很长时间来获得干净的窗口和界面(尤其是一些客户喜欢的黑暗"主题).
  • 现代用户界面.一点个人经验,但它的相似之处在于它有更现代的窗户设计,以及一个大的风格集.我看到它经常被使用.
  • 极乐世界.同样,经验不多,但似乎很活跃.我没有看到它像其他两个一样被使用.

当然,这些包括许多其他 Metro 主题.还有其他可用的主题包,如果客户想要现代设计,我发现 XAML 工具包中的材料设计 很棒(也可识别,来自 Google).

看起来您是从头开始制作样式,但上面的内容可能仍然对您简单地用于窗口有用.如果你想自己去做,有很多答案的冗长讨论 此处.

对于弯角,如评论中所述,这是 WPF 在不同操作系统上的默认行为的结果.它尝试选择默认样式以与当前操作系统最佳融合.对于大多数仅使用默认主题的应用程序,这通常无关紧要.

但是,当您自己为所有内容设置样式时,它确实会对您手动配置的内容造成严重破坏,因为某些与您设置的主题配合良好的属性可能会有所不同 - 例如圆角.

有两种选择.

  1. 显式设置所有属性,使其看起来完全符合您的要求.这样做意味着即使基本"主题发生变化,它仍然看起来不错.这就是上面那些库的工作方式——它们完全定义了一种风格.问题是您必须手动在不同的主题上对其进行测试,这需要一些工作.
  2. 手动设置基本主题.(也可用于选项 1 中的测试!)您可以手动覆盖您的应用使用的主题,而不是让它使用操作系统的默认主题,就像您应用其他自定义主题或您自己的主题一样:

<块引用>

<ResourceDictionary Source="/PresentationFramework.Aero, Version=3.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml"/></App.Resources>

出于某种原因,除非用引号括起来,否则上述内容不会作为代码出现...

I have annoying appearance differences between Windows 10 devices and Windows 7 devices.

I am using WindowStyle="None" and DockPanel directly inside my Window element.

What I don't get is why there is still a border? Why are the borders on buttons, textboxes, comboboxes, etc. rounded?

It seems this is related to Aero. Is there a way I can stop my application from using Aero? I'm assuming there is another presentation framework related to Windows 10 but do not know what it is called to force it.

Would a BorderBrush be the easiest way to resolve this?

<Window x:Class="CBD.Presentation.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:CBD.Presentation"
        Title="CBD" Height="760" Width="944" WindowStartupLocation="CenterScreen"
        WindowStyle="None" SizeChanged="Window_SizeChanged" MinWidth="944" MinHeight="760"
        Icon="favicon.ico">
    <DockPanel x:Name="Root_Window" Background="Black">
        <!--Application stuff here -->
    </DockPanel>
</Window>

Windows 7 display:

Windows 10 display:

Everything still functions properly but the way some textboxes and buttons are setup, parts of letters are missing.

解决方案

I think both these is something a lot of people are going to stumble upon when they really start customizing the style of their applications. There's some well established shortcuts to both problems, such as using existing style/libraries for WPF:

There's a few common Window and style libraries I see:

  • MahApps.Metro is a great library I've used for a long time for getting clean windows and interfaces (especially with 'dark' themes some customers love).
  • Modern UI. Little personal experience, but it's similar in that it has more modern window designs, as well as a big style set. I've seen it used frequently.
  • Elysium. Again, not much experience, but seems active. I've not seen it used as much as the other two.

These, of course, include a lot of other Metro theming. There are other theme packs available, I've found the Material Design In XAML Toolkit great if a client want's a modern design (Also recognizable, being from Google).

It looks like you're making your style from scratch, but the above might still be useful for you to simply use for the windows. If you want to go at it yourself there's a lengthy discussion with lot's of answers here.

For the curved corners, as discussed in the comments, this is as a result of WPF's default behavior on different operating systems. It attempts to select a default style to blend in best with the current operating system. For most applications that just use the default theme, this doesn't often matter.

When you're styling everything yourself though, it really plays havoc with what you have manually configured, because some properties that work well with the theme you set things up on might be different - like the rounded corners.

There's two options.

  1. Explicitly set all the properties, so it looks exactly how you want it. Doing this means that even if the 'base' theme changes, it will still look good. This is how those libraries above do things - they define a style completely. Problem is you will have to test it on the different themes manually and it's a bit of work.
  2. Manually set the base theme. (Can also be used for testing in option 1!) You can override which theme your app uses manually rather than letting it use the default for the operating system in much the same way you apply other custom themes, or maybe your own:

<App.Resources>
  <ResourceDictionary Source="/PresentationFramework.Aero, Version=3.0.0.0,
      Culture=neutral, PublicKeyToken=31bf3856ad364e35,
      ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml"/>
</App.Resources>

For some reason the above would not appear as code unless encased in quotes...

这篇关于WPF:Windows 7 与 Windows 10 外观对比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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