I can not solve this problem. There is a user control with several Textbox. A template containing 6 such controls has also been created. Using the template, tabs of the main application window are populated. The template is associated with the view model. I can not find a way to get to the IsEnabled property of each specific textbox from the main window? For more details on code examples referring to the English version of the stack: here . Can anyone have any ideas?

  • one
    Add your code examples directly to this question. - Vadim Ovchinnikov February

2 answers 2

Well, you can do it through the ViewModel :

 public class Module: INotifyPropertyChanged { private double _ch1; public double Ch1 { get { return this._ch1; } set { if (_ch1 == value) return; _ch1 = value; OnPropertyChanged("Ch1"); } } private bool _isEnbl; public bool IsEnbl { get { return this._isEnbl; } set { if (_isEnbl== value) return; _isEnbl= value; OnPropertyChanged("IsEnbl"); } } 

And you simply bind here:

 <UserControl x:Class="WpfApplication4.MyModuleFrame" <!-- ... --> x:Name="mUserControl"> <Grid> <!-- ... --> <TextBox Text="{Binding ItemSource.Ch1, ElementName=mUserControl}" IsEnabled="{Binding ItemSource.IsEnbl, ElementName=mUserControl}" Name="txtCh1"/> <!-- other textboxes --> </Grid> </UserControl> 
  • Brilliantly simple! Thank you very much, Sergey, now it works! @ Sergey - S. Neuer
  public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged([CallerMemberName] string property = "") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property)); } 

As a small life hack, in order not to specify the name of the [CallerMemberName] property do it for you, respectively:

 public double Ch1 { get { return this._ch1; } set { if (_ch1 == value) return; _ch1 = value; NotifyPropertyChanged(); } 

}

It may help :)

  • Thank! Useful! @Morgomirius - S. Neuer