WPF将一个控件的启用属性绑定到CheckBox

时间:2014-10-13 10:06:15

标签: c# wpf xaml

我正在尝试使用以下XAML将控件的IsEnabled属性绑定到IsChecked的{​​{1}}属性,因此将根据{启用或禁用控件{1}}状态。

CheckBox

它不起作用。有什么问题?

编辑:感谢您的所有评论!下面是来自style.xaml,现在基于@Ivan的评论。禁用时,TextBlock设置为“灰显”(取自here

CheckBox

1 个答案:

答案 0 :(得分:2)

尽管这是一个古老的问题,但这仍然是其他人对标题 中的原始问题的答案,像我一样在这里绊脚了:

<DockPanel>
        <CheckBox x:Name="CbxAgree" Content="Agreed" FontSize="21" 
                  Background="Black" Foreground="Black"
                  VerticalAlignment="Center" Margin="8 4 16 4"
                  IsChecked="True" />

        <Button VerticalAlignment="Stretch" 
                Background="White" Foreground="Black" 
                Content="Submit"  FontSize="22"
                IsEnabled="{Binding ElementName=CbxAgree, Path=IsChecked}"/>
</DockPanel>