我可以这样做吗?
<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>
答案 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>