. , UserControl DataContext . :
UserControlExample() {
InitializeComponent();
RootElement.DataContext = this;
}
RootElement - , RootElement ( Grid ) UserControl.
:
<TextBox x:Name="MainTextBox" IsEnabled={Binding IsEnabled} />
, TextBox DataContext .
, , UserControl IsEnabled , :
<Grid>
<UserControlExample IsEnabled={Binding CanModify} />
</Grid>
This way you keep your concerns separate. Subelements are not important, which reflects UserControl. They just need to know how to enable / disable when the IsEnabledcontrol property is flipped.
sub-controls IsEnabled bound to --> (UserControlExample is DataContext)
UserControlExample.IsEnabled bound to --> (VM is DataContext)
VM.CanModify
source
share