The situation is a little bit more complex than in the post I mentioned as duplicate, so here is a working solution:
As far as I know, you need to create a DependencyProperty (DP) on your UserControl with the Checkbox and bind the Checkbox.IsChecked
property to this DP.
Then you can bind your usr2
control on the DP.
Here is the code:
usr1.xaml
<UserControl [...]>
<Grid>
<CheckBox x:Name="MyCheckbox" IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:usr1}}, Path=MyCheckboxIsChecked, Mode=TwoWay}" />
</Grid>
</UserControl>
usr1.xaml.cs (code behind)
public partial class usr1: UserControl
{
public usr1()
{
InitializeComponent();
}
public static readonly DependencyProperty MyCheckboxIsCheckedProperty = DependencyProperty.Register(
"MyCheckboxIsChecked", typeof(bool), typeof(usr1), new PropertyMetadata(default(bool)));
public bool MyCheckboxIsChecked
{
get
{
return (bool)GetValue(MyCheckboxIsCheckedProperty);
}
set
{
SetValue(MyCheckboxIsCheckedProperty, value);
}
}
}
usr2.xaml
<UserControl [...]>
<Grid>
<TextBox x:Name="MyTextBox" />
</Grid>
</UserControl>
MainWindow.xaml
<Grid>
<StackPanel>
<local:usr1 x:Name="usr1Control" />
<local:usr2 IsEnabled="{Binding ElementName=usr1Control, Path=MyCheckboxIsChecked}" />
</StackPanel>
</Grid>