开发者

WPF: Resources in a GroupBox header

开发者 https://www.devze.com 2023-01-08 23:11 出处:网络
Can I do something like this? <GroupBox.Header> <GroupBox.Header.Resources> <Style TargetType=\"Label\">

Can I do something like this?

                <GroupBox.Header>
                    <GroupBox.Header.Resources>
                        <Style TargetType="Label">
                            <Setter Property="Foreground" Value="White"/>
                        </Style>
                    </Gr开发者_开发百科oupBox.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>


You're setting the Header property of a GroupBox object to a StackPanel object. If you want resources available in the Header, add them to the Resources of the StackPanel object:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号