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

时间:2020-05-29 22:14:17

标签: c# wpf xaml resources wpf-style

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

1[System.Byte],System.Collections.Generic.List

这就是我在MainWindow.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>

我的问题是属性(如背景)仅在运行时可见。这可能很明显,但我真的不明白。

1 个答案:

答案 0 :(得分:1)

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

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

enter image description here

这是我的MainWindow.xaml.cs:

<Window x:Class="StyleTest.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:StyleTest"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" Style="{DynamicResource MainWindowStyle}">
    <Grid>

    </Grid>
</Window>