2014-11-04 45 views
3

我CheckBox和RadioButton。我需要IsEnabled屬性綁定到財產器isChecked綁定IsEnabled被檢查WPF

<CheckBox x:Name="check_box" Content="CheckBox" IsChecked="True" /> 

<RadioButton Content="Depending Component" IsChecked="True" Margin="15,3,0,0" IsEnabled="{Binding check_box.IsChecked}" /> 

有沒有辦法做到這一點無需編寫代碼?

回答

10

是的,你需要使用的ElementNameMSDN)結合:

<CheckBox x:Name="check_box" Content="CheckBox" IsChecked="True" /> 
<RadioButton IsEnabled="{Binding ElementName=check_box, Path=IsChecked, 
           TargetNullValue=false}" .../> 
+0

'IsChecked'是可空'' -typed,所以理想的結合應該設置一些'TargetNullValue',如'返回FALSE。 – 2014-11-04 17:11:04

+0

@MikeStrobel我不知道你可以指定;多麼酷的功能!添加到我的答案,並感謝您的信息。 – BradleyDotNET 2014-11-04 17:13:50