gpt4 book ai didi

c# - Visual Studio WPF 设计器不使用覆盖的 SystemColors

转载 作者:太空宇宙 更新时间:2023-11-03 14:49:21 25 4
gpt4 key购买 nike

我目前正在尝试覆盖 WPF 系统颜色。来自 here我发现这可以通过创建一个新的 SolidColorBrush 资源来完成,例如使用键 x:Key="{x:Static SystemColors.WindowBrushKey}" 来更改窗口的背景颜色。

这已经有效,但是 Visual Studio WPF 设计器不会将新颜色显示为窗口的背景。

从一个干净的 WPF 应用程序开始,这就是我的主窗口的 XAML 代码:

<Window x:Class="TestOverwriteSystemColor.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"
xmlns:local="clr-namespace:TestOverwriteSystemColor"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Orange" />
</Window.Resources>
<Grid>

</Grid>
</Window>

在 Visual Studio 设计器中,它看起来像这样:

Visual Studio WPF Designer View

如果我运行它,这就是生成的应用程序:

enter image description here

同时将 SolidColorBrush 资源添加到 App.xaml 资源不会改变这一点。 Designer 中也使用了新定义的 SystemColor,我错过了什么?

最佳答案

正如 Otiel 提到的,这可能是 Visual Studio 中的一个错误,所以我在 Microsoft 开始了一个问题报告。目前正在考虑中:https://developercommunity.visualstudio.com/content/problem/633508/overwriting-resource-windowbrushkey-does-not-have.html

关于c# - Visual Studio WPF 设计器不使用覆盖的 SystemColors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52455097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com