title: Changing a textbox's IsEnabled property from button command in another window isn't working?
body: <p>I have two windows. I want to click a button in one window and it enable two textboxes in another window. My code seems correct, I have the data context set like </p>
  
  <pre><code>&lt;Window.DataContext&gt;
      &lt;local:MainWindowViewModel/&gt;
  &lt;/Window.DataContext&gt;
  </code></pre>
  
  <p>and the inotifypropertychanged is also set. There are no binding errors in the output window and I know inotifypropertychanged works because a button in the same window changes the isenabled property so the issue must be that the button I want to use is in another window. </p>
  
  <p>The whole thing works by binding the IsEnabled property of the two textboxes to a property IsLoggedIn in the view model. In the window with the button I have the button binded to buttoncommands in their own class. The button commands simply call a method in the view model as such</p>
  
  <pre><code>class ButtonCommands : ICommand
  {
      private readonly MainWindowViewModel viewModel;
  
      public ButtonCommands(MainWindowViewModel viewModel)
      {
          this.viewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel));
      }
  
      public event EventHandler CanExecuteChanged;
  
      public bool CanExecute(object parameter) =&gt; true;
  
      public void Execute(object parameter)
      {
          viewModel.SwitchEnabled();
      }
  }
  </code></pre>
  
  <p>The view model looks like this, notice the SwitchEnabled method in the viewModel,again, which is the method that the button binds to.</p>
  
  <pre><code>class MainWindowViewModel : INotifyPropertyChanged
  {
  
      public MainWindowViewModel()
      {
          ButtonCommands = new ButtonCommands(this);
  
      }
      private bool _isLoggedIn = false;
  
      public bool IsLoggedIn
      {
          get =&gt; _isLoggedIn;
          set
          {
              if(_isLoggedIn != value)
              {
                  _isLoggedIn = value;
                  OnPropertyChanged("IsLoggedIn");
              }
          }
      }
  
      public void SwitchEnabled()
      {
          IsLoggedIn = true;
      }
  
      public ICommand ButtonCommands { get; }
      /// &lt;summary&gt;
      /// if property is changed, invoke new propertychanged event
      /// &lt;/summary&gt;
      /// &lt;param name="propertyName"&gt;&lt;/param&gt;
      public void OnPropertyChanged(string propertyName)
      {
          this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
      }
  
      /// &lt;summary&gt;
      /// default PropertyChanged event
      /// &lt;/summary&gt;
      public event PropertyChangedEventHandler PropertyChanged;
  }}
  </code></pre>
  
  <p>When I debug the code the property value is correct, it goes to true and if you look at the xaml value it shows true, but the textboxes never become enabled. I have spent over a week trying to figure this out. I know that this does not entirely follow mvvm but I am just looking to make this work. 
  The code for the mainwindow is:</p>
  
  <pre><code>&lt;Window.DataContext&gt;
      &lt;local:MainWindowViewModel/&gt;
  &lt;/Window.DataContext&gt;
  
  &lt;Window.Resources&gt;
      &lt;Style TargetType="TextBox"&gt;
          &lt;Style.Triggers&gt;
              &lt;DataTrigger Binding="{Binding IsLoggedIn}" Value="True"&gt;
                  &lt;Setter Property="IsEnabled" Value="True"/&gt;
              &lt;/DataTrigger&gt;
          &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
  &lt;/Window.Resources&gt;
  
  &lt;StackPanel&gt;
      &lt;TextBox Background="Red" Height="100" IsEnabled="{Binding IsLoggedIn}"/&gt;
      &lt;TextBox Background="Blue" Height="100" IsEnabled="{Binding IsLoggedIn}"/&gt;
      &lt;Button Content="Push me" FontSize="40" Background="Yellow" Height="100" Command="{Binding ButtonCommands}"/&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>the code for window2 is:</p>
  
  <pre><code>&lt;Window.DataContext&gt;
      &lt;local:MainWindowViewModel/&gt;
  &lt;/Window.DataContext&gt;
  &lt;Grid&gt;
      &lt;Button Height="100" Background="Red" Content="Push me too" FontSize="40" Command="{Binding ButtonCommands}"/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>As you can see, I have also tried data triggers but they too do not work. There just seems to be an issue with making ui changes from another window. Any help would be greatly appreciated.</p>