title: How to access WPF user control's elements inside viewmodel which is a content of tab items?
body: <p>In WPF app I have a user control which consists of four TextBoxes. Six units of such user controls form a datatemplate using which I populate tab items of my TabControl in main window. The content of the datatemplate's bound through viewmodel to data layer. 
  My problem is, I can't find a way to access IsEnabled property of each individual TextBox from the view (main window). Using VisualTreeHelper doesn't help to exactly localize TextBoxes, because viewmodel which is the content of each tab item, is not a Visual. So as maximum I get a reference to one TextBox instance, but it works on all tabs simultaneously.
  Can anyone help me please with this?</p>
  
  <p>EDIT:
  below the simplified code snippets for better understanding my problem</p>
  
  <p>UserControl XAML:</p>
  
  <pre><code>UserControl x:Class="WpfApplication4.MyModuleFrame"
       &lt;!-- ... --&gt;
       x:Name="mUserControl"&gt;
    &lt;Grid&gt;
       &lt;!-- ... --&gt;
      &lt;TextBox Text="{Binding ItemSource.Ch1, ElementName=mUserControl}" Name="txtCh1"/&gt;
      &lt;!-- other textboxes --&gt;
    &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>UserControl code-behind:</p>
  
  <pre><code>namespace WpfApplication4
  {
    public partial class MyModuleFrame : UserControl
    {
      public MyModuleFrame()
      {
          InitializeComponent();
      }
  
      public Module ItemSource
      {
          get { return (Module)GetValue(ItemSourceProperty); }
          set { SetValue(ItemSourceProperty, value); }
      }
          // Using a DependencyProperty
          public static readonly DependencyProperty ItemSourceProperty =
          DependencyProperty.Register("ItemSource", typeof(Module), typeof(MyModuleFrame), new PropertyMetadata(default(Module)));
    }
  }
  </code></pre>
  
  <p>Module.cs:</p>
  
  <pre><code>namespace WpfApplication4
  {
    public class Module: INotifyPropertyChanged
    {
  
      private double _ch1;
      public double Ch1
      {
          get { return this._ch1; }
          set
          {
              if (_ch1 == value) return;
              _ch1 = value;
              OnPropertyChanged("Ch1");
          }
      }
      ...
      ...
      ...
      public event PropertyChangedEventHandler PropertyChanged;
  
      private void OnPropertyChanged(string aNameOfProperty)
      {
          if (PropertyChanged != null)
          PropertyChanged(this, new PropertyChangedEventArgs(aNameOfProperty));
      }
  </code></pre>
  
  <p>ViewModel.cs:</p>
  
  <pre><code>namespace WpfApplication4
  {
  public class MainViewModel: INotifyPropertyChanged
  {
      public Module Module1 { get; set; }
      public Module Module2 { get; set; }
      public Module Module3 { get; set; }
      public Module Module4 { get; set; }
      public Module Module5 { get; set; }
      public Module Module6 { get; set; }
  
      public MainViewModel()
      {
          Module1 = new Module() { Number = "1", Ch1 = 123.4, Ch2 = 123.4, Ch3 = 123.4, Ch4 = 123.4 };
          Module2 = new Module() { Number = "2", Ch1 = 123.4, Ch2 = 123.4, Ch3 = 123.4, Ch4 = 123.4 };
          Module3 = new Module() { Number = "3", Ch1 = 123.4, Ch2 = 123.4, Ch3 = 123.4, Ch4 = 123.4 };
          Module4 = new Module() { Number = "4", Ch1 = 123.4, Ch2 = 123.4, Ch3 = 123.4, Ch4 = 123.4 };
          Module5 = new Module() { Number = "5", Ch1 = 123.4, Ch2 = 123.4, Ch3 = 123.4, Ch4 = 123.4 };
          Module6 = new Module() { Number = "6", Ch1 = 123.4, Ch2 = 123.4, Ch3 = 123.4, Ch4 = 123.4 };
      }
  ...        
      public event PropertyChangedEventHandler PropertyChanged;
      protected virtual void RaisePropertyChanged(string propertyName)
      {
          this.VerifyPropertyName(propertyName);
          PropertyChangedEventHandler handler = this.PropertyChanged;
          if (handler != null)
          {
              var e = new PropertyChangedEventArgs(propertyName);
              handler(this, e);
          }
      }
  </code></pre>
  
  <p>Main window XAML:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication4.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      &lt;!-- ... --&gt;
      Title="Window1" Height="800" Width="1000" x:Name="wndMain"
      DataContext = "{StaticResource MainViewModel}"&gt;
  &lt;Window.Resources&gt;
      &lt;DataTemplate x:Key="tabTemplate"&gt;
          &lt;Grid&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="1*" /&gt;
                  &lt;ColumnDefinition Width="1*" /&gt;
                  &lt;ColumnDefinition Width="1*" /&gt;
                  &lt;ColumnDefinition Width="1*" /&gt;
                  &lt;ColumnDefinition Width="1*" /&gt;
                  &lt;ColumnDefinition Width="1*" /&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition Height="30" /&gt;
                  &lt;RowDefinition Height="210" /&gt;
                  &lt;RowDefinition Height="30" /&gt;
                  &lt;RowDefinition Height="*" /&gt;
              &lt;/Grid.RowDefinitions&gt;
              &lt;loc:MyModuleFrame Name="mmf1" Grid.Row="1" Grid.Column="0" ItemSource="{Binding Module1}"/&gt;
              &lt;loc:MyModuleFrame Name="mmf2" Grid.Row="1" Grid.Column="1" ItemSource="{Binding Module2}"/&gt;
              &lt;loc:MyModuleFrame Name="mmf3" Grid.Row="1" Grid.Column="2" ItemSource="{Binding Module3}"/&gt;
              &lt;loc:MyModuleFrame Name="mmf4" Grid.Row="1" Grid.Column="3" ItemSource="{Binding Module4}"/&gt;
              &lt;loc:MyModuleFrame Name="mmf5" Grid.Row="1" Grid.Column="4" ItemSource="{Binding Module5}"/&gt;
              &lt;loc:MyModuleFrame Name="mmf6" Grid.Row="1" Grid.Column="5" ItemSource="{Binding Module6}"/&gt;
          &lt;/Grid&gt;
      &lt;/DataTemplate&gt;
  &lt;/Window.Resources&gt;
    &lt;Grid&gt;
      &lt;TabControl Grid.Row="0" Name="tabHolder" SelectedIndex="{Binding Selected}" HorizontalAlignment="Stretch" Margin="10" VerticalAlignment="Stretch" Height="Auto" Width="Auto" 
                  ContentTemplate="{StaticResource tabTemplate}"&gt;
      &lt;/TabControl&gt;
  
    &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>and Main window code-behind:</p>
  
  <pre><code>namespace WpfApplication4
  {
    public partial class Window1 : Window
    {
  
      protected List&lt;MainViewModel&gt; viewmodels;
  
      public Window1()
      {
          InitializeComponent();
  
          viewmodels = new List&lt;MainViewModel&gt;();
          viewmodels.Add(new MainViewModel());
          viewmodels.Add(new MainViewModel());
          viewmodels.Add(new MainViewModel());
  
          tabHolder.ItemsSource = viewmodels;
      }
    }
  }
  </code></pre>