【发布时间】:2016-08-02 04:49:13
【问题描述】:
参考这个问题:WPF Databinding: How do I access the "parent" data context?
我想做一些类似的事情,但是对于 Groupbox 的标题(因为标题与 Box 被禁用无关,因此始终为黑色,而其余部分为浅灰色。如果全部的话,这对我来说有点奇怪盒子的内容是灰色的,上面是灰色的,但是盒子标题本身是黑色的。
所以我尝试使用 flq 的链接问题中提到的方法将标题文本块的 isEnabled 属性简单地绑定到 groupbox 的 isEnabled 属性,但似乎我的绑定在某些时候失败了,我不知道具体在哪里以及为什么。
这是我当前的代码:
<GroupBox Header="Change Steps" Grid.Row="2" Grid.ColumnSpan="3" Name="gbChangeSteps">
<GroupBox.Style>
<Style TargetType="GroupBox">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" FontWeight="Bold" Height="19" Foreground="Black" IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}, Path=isEnabled}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupBox.Style>
<!-- ... (some non relevant Content)-->
</GroupBox>
【问题讨论】:
标签: wpf data-binding