WPF:GroupBox标头中的资源

时间:2010-07-28 03:13:56

标签: wpf styles

我可以这样做吗?

                <GroupBox.Header>
                    <GroupBox.Header.Resources>
                        <Style TargetType="Label">
                            <Setter Property="Foreground" Value="White"/>
                        </Style>
                    </GroupBox.Header.Resources>
                    <StackPanel Orientation="Horizontal">
                        <Label Content="Realtime Event Viewer" VerticalAlignment="Center"/>
                        <Label Content="Watching: " Margin="20,0,0,0" VerticalAlignment="Center"/>
                        <Label Content="{Binding MonitorServerName}" VerticalAlignment="Center"/>
                    </StackPanel>
                </GroupBox.Header>

1 个答案:

答案 0 :(得分:3)

您正在将GroupBox对象的Header属性设置为StackPanel对象。如果您希望Header中有可用资源,请将它们添加到StackPanel对象的Resources:

<GroupBox.Header>
    <StackPanel Orientation="Horizontal">
        <StackPanel.Resources>
            <Style TargetType="Label">
                <Setter Property="Foreground" Value="White"/>
            </Style>
        </StackPanel.Resources>
        <Label Content="Realtime Event Viewer" VerticalAlignment="Center"/>
        <Label Content="Watching: " Margin="20,0,0,0" VerticalAlignment="Center"/>
        <Label Content="{Binding MonitorServerName}" VerticalAlignment="Center"/>
    </StackPanel>
</GroupBox.Header>