基于在设计器中未显示的窗口上设置的样式(仅在运行时中)

本文关键字:样式 设置 运行时 显示 窗口 | 更新日期: 2023-09-27 18:34:22

很奇怪的场景。我有以下应用程序.xaml

<Application x:Class="BrokenBG.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <Style x:Key="WindowStyleBase" TargetType="ContentControl" >
            <Setter Property="Background" Value="Red" />
          </Style>
        <Style x:Key="WindowStyle" TargetType="{x:Type Window}" BasedOn="{StaticResource WindowStyleBase}" />
    </Application.Resources>
</Application>

还有一个带有样式集的普通空窗口:

<Window x:Class="BrokenBG.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Style="{StaticResource WindowStyle}">
    <Grid>
    </Grid>
</Window>

当我运行该应用程序时,一切都很好。我看到红色的bg。但我在设计师身上看不到它。上面的代码是我在另一个更大的项目中遇到的重现案例。

当我将窗口样式从WindowStyle更改为WindowStyleBase时,我可以直接在设计器中看到红色背景色。

这可以解决吗?我的窗口有一个深色主题,因此我无法在Visual Studio/Blend中设计视图,因为在运行时背景是白色和黑色(我的文本是白色的(

看起来设计师在基于解析方面有问题?(不确定(

基于在设计器中未显示的窗口上设置的样式(仅在运行时中)

一件事是有效的,即使它不会编译。您可以将静态资源更改为动态资源。

它会突然开始在设计器中工作,但这不会编译。

我什至将红色更改为蓝色,设计师进行了更新。