简体   繁体   中英

Visual Studio WPF Designer does not use overwritten SystemColors

I am currently trying to overwrite the WPF system colors. From here I found out that this can be done by creating a new SolidColorBrush resource with for example the key x:Key="{x:Static SystemColors.WindowBrushKey}" to change the Window's background color.

This already works however the Visual Studio WPF Designer does not show the new color as background of the Window.

Starting with a clean WPF App this is what my XAML code looks like for the MainWindow:

<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>

In the Visual Studio Designer this looks like this:

Visual Studio WPF设计器视图

And that is the resulting application if I run it:

在此处输入图片说明

Also adding the SolidColorBrush Resource to the App.xaml resource does not change this. What am I missing that the newly defined SystemColor is also used in the Designer?

As Otiel mentioned this probably is a bug in Visual Studio, so I started a problem report at Microsoft. For now it is Under Consideration: https://developercommunity.visualstudio.com/content/problem/633508/overwriting-resource-windowbrushkey-does-not-have.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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