简体   繁体   English

WPF/XAML 看起来不像系统主题

[英]WPF/XAML doesn't look like system theme

I would expect a default project for WPF to use the exact system theme, but the default theme for WPF looks somewhat akin to Windows 10, but not quite.我希望 WPF 的默认项目使用确切的系统主题,但 WPF 的默认主题看起来有点类似于 Windows 10,但不完全是。 And rather ugly if I had my opinion.如果我有我的意见,那就相当丑陋了。 My question is - how do I make WPF follow system theme?我的问题是 - 如何让 WPF 遵循系统主题?

Screenshot below is running in Windows 11. It's just a deafult project using File > New Project > WPF Application下面的屏幕截图在 Windows 11 中运行。它只是一个使用 File > New Project > WPF Application 的默认项目

显示 WPF 的图像

This screenshot is from some random Visual Studio menu.此屏幕截图来自一些随机的 Visual Studio 菜单。 Obviously these buttons look much different.显然,这些按钮看起来大不相同。

在此处输入图片说明

I would expect a default project for WPF to use the exact system theme ...我希望 WPF 的默认项目使用确切的系统主题......

I am afraid your expectation is wrong.恐怕你的期望是错误的。 The default WPF templates have not been updated for Windows 11 and I strongly doubt they ever will be. Windows 11 的默认 WPF 模板尚未更新,我强烈怀疑它们是否会更新。

If you want a modern UI experience in your Windows apps, I would recommend you to look into using WinUI (3).如果您想在 Windows 应用程序中获得现代 UI 体验,我建议您考虑使用WinUI (3)。 It's the the next generation native UI layer for Windows, including full-trust desktop apps.它是适用于 Windows 的下一代本机 UI 层,包括完全信任的桌面应用程序。

I think the closest you will get to this is by using ModernWPF .我认为您最接近的是使用ModernWPF

This is basically a port of WinUI to WPF, but only up until WinUI 2.6 when Microsoft introduced the Windows 11 styles.这基本上是 WinUI 到 WPF 的移植,但直到 Microsoft 引入 Windows 11 样式的 WinUI 2.6 为止。 The project currently has open issues logged for Windows 11 styles but it's still up in the air as for whether it'll gain support for these anytime soon.该项目目前有针对 Windows 11 样式记录的未解决问题,但它是否会很快获得对这些样式的支持仍然悬而未决。

I cannot answer your question, but I suspect that you just want to make the appearance more attractive.我无法回答你的问题,但我怀疑你只是想让外表更有吸引力。

To do this, you can use the style libraries.为此,您可以使用样式库。 For example here.例如这里。 I used it myself for applications.我自己将它用于应用程序。 Very easy to learn:非常容易学习:

https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit

And here.和这里。 I haven't used it, but it looks interesting:我没用过,但看起来很有趣:

https://microsoft.github.io/microsoft-ui-xaml/ https://microsoft.github.io/microsoft-ui-xaml/

There's a WinUI 3 port for WPF called WPFUI . WPF 有一个 WinUI 3 端口,称为WPFUI It requires some simple steps to modernize your WPF application and make it look like Windows 11 new UI (Unlike XAML Island where you have to do dozens of steps and still need to change your UI codes and create another project in the solution)它需要一些简单的步骤来使您的 WPF 应用程序现代化并使其看起来像 Windows 11 新 UI(与 XAML 岛不同,您必须执行几十个步骤,但仍需要更改 UI 代码并在解决方案中创建另一个项目)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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