在样式化GroupBox时需要帮助 [英] Need Help with Styling a GroupBox

查看:100
本文介绍了在样式化GroupBox时需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XAML中定义了一个要在所有Groupbox上使用的样式,但是有一个Groupbox的背景属性必须与其他属性不同.我尝试在后台代码中设置此属性,但是没有运气.有任何想法吗?

I defined a Style in my XAML to be used on all Groupboxes, but there''s ONE groupbox''s background property that has to be different from the others. I tried setting this property in the code-behind, but no luck. Any ideas?

以下是样式的代码:

<!--<span class="code-comment">A style that formats all groupboxes--></span>
<Style TargetType="GroupBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupBox">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="White" BorderThickness="2,2,2,1" CornerRadius="0,12,0,0" >
<ContentPresenter Margin="4" ContentSource="Header" RecognizesAccessKey="True" />
</Border>
<Border Grid.Row="1" BorderBrush="White" BorderThickness="2,0,2,2" CornerRadius="0,0,0,12" >
<ContentPresenter Margin="4" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

推荐答案

如果您需要做的就是让一个组框在样式上与其他组框略有不同,那么您要做的就是创建一个针对组框的新样式,并为其提供密钥.默认情况下(只要您将其添加到上述分组框之后),它将继承该分组框的设置,并且您可以适当地更改背景属性.然后,您所要做的就是将样式应用于相关的分组框-您在这里有使用的关键.

If all you need to do is have one groupbox that behaves slightly differently to the others in it''s styling, all you need to do is create a new style that targets a groupbox, and give it a key. By default, (as long as you add it after the groupbox above) it will inherit the settings of the groupbox, and you can change the background property as appropriate. All you need do then is apply the style to the groupbox in question - you have the key to use here.


这篇关于在样式化GroupBox时需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆