WPF窗口属性仅在运行时可见

问题描述 投票:0回答:1

我是XAML入门者,也自己学习。因此,在App.xaml中,我具有以下样式:

<Application.Resources>
        <Style x:Key="Colors" TargetType="{x:Type Control}">
            <Setter Property="Background" Value="#FF404040"/>
            <Setter Property="Foreground" Value="#FF25CBDA"/>
            <Setter Property="BorderBrush" Value="#FF25CBDA"/>
        </Style>

        <Style x:Key="BaseWindowStyle" TargetType="Window" BasedOn="{StaticResource Colors}">
            <Setter Property="Title" Value="MainWindow"/>
            <Setter Property="WindowState" Value="Normal"/>
            <Setter Property="Icon" Value="Icon.ico"/>
        </Style>

        <Style x:Key="MainWindowStyle" TargetType="{x:Type Window}" BasedOn="{StaticResource BaseWindowStyle}">
            <Setter Property="ResizeMode" Value="CanResize"/>
            <Setter Property="ShowInTaskbar" Value="True"/>
        </Style>
</Application.Resources>

这就是我在MainWindow.xaml中使用样式的方式:Style="{DynamicResource MainWindowStyle}"我的问题是这些属性(如背景)仅在运行时可见。

可能有点明显,但我真的不明白。

感谢您的帮助。

c# wpf xaml resources styles
1个回答
0
投票

欢迎,DeJoon!目前尚不清楚您没有得到什么。您想发生什么,或期望发生什么?您是在说您不知道背景颜色是什么,直到您运行该应用程序,但您想在设计时看到它?您应该能够通过XAML设计器看到颜色和属性。

我接受了您的代码,因为没有该文件,因此注释掉了与“ icon.ico”相关的一行,并且我可以从设计者那里看到您的背景色为深灰色。看到这里:

© www.soinside.com 2019 - 2024. All rights reserved.