title: XAML using radio buttons to enable and disable textbox with databinding
body: <p>I am trying to figure out how to enable and disable textboxes with radio buttons and data binding. It seems like I should be able to bind the textbox IsEnabled to a boolean and modify that value but I can't quite get it to work.  I want to have several sets of radio buttons and textboxes so I want a generic way to handle the problem.  I tried to use a converter but since I am not using any x:Names I am not sure those would be helpful in this case.  I can get them to enable/disable the radio buttons but that is not what I want to do.   My code shows mostly the solution I am trying for the first textbox.</p>
  
  <p>Xaml Code</p>
  
  <pre><code>    &lt;Grid&gt;
      &lt;StackPanel&gt;
          &lt;RadioButton GroupName="grp1" Content="Enable TextBox"  IsEnabled="{Binding Bttn1, Mode=TwoWay}" IsChecked="{Binding Bttn1}" Checked="RadioButton_Checked" Unchecked="RadioButton_UnChecked" /&gt;
          &lt;RadioButton GroupName="grp1" Content="Disable TextBox" IsEnabled="{Binding Bttn2}" /&gt;
          &lt;TextBox IsEnabled="{Binding Txtbx1, Mode=TwoWay}" BindingGroup="{Binding grp1}" &gt;&lt;/TextBox&gt;
  
          &lt;RadioButton GroupName="grp2" Content="Enable TextBox"  IsEnabled="{Binding Bttn3, Mode=TwoWay}" IsChecked="{Binding Bttn3}" Checked="RadioButton_Checked" Unchecked="RadioButton_UnChecked" /&gt;
          &lt;RadioButton GroupName="grp2" Content="Disable TextBox" IsEnabled="{Binding Bttn4}" /&gt;
          &lt;TextBox IsEnabled="{Binding Txtbx2, Mode=TwoWay}" BindingGroup="{Binding grp2}" &gt;&lt;/TextBox&gt;
      &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>ViewModel Code</p>
  
  <pre><code>    private bool _bttn1;
      private bool _bttn2;
      private bool _bttn3;
      private bool _bttn4;
      private bool _txtbx1;
      private bool _txtbx2;
  
      public bool Bttn1
      {
          get
          {
              return(_bttn1);
          }
  
          set
          {
              _bttn1 = value;
              _txtbx1 = false;
              RaisePropertyChanged(Txtbx1.ToString());
          }
  
      }
  
      public bool Bttn2
      {
          get
          {
              return (_bttn1);
          }
  
          set
          {
              _bttn1 = value;
              _txtbx1 = false;
              RaisePropertyChanged(Txtbx1.ToString());
          }
  
      }
  
      public bool Txtbx1
      {
          get
          {
              return (_txtbx1);
          }
  
          set
          {
              _txtbx1 = false;
          }
      }
  </code></pre>
  
  <p>Further down I have</p>
  
  <pre><code>    public event PropertyChangedEventHandler PropertyChanged;
  
      protected void RaisePropertyChanged(string name)
      {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(name));
          }
      }
  
  
      private void RadioButton_Checked(object sender, RoutedEventArgs e)
      {
          Handle(sender as RadioButton);
      }
  
      private void RadioButton_UnChecked(object sender, RoutedEventArgs e)
      {
          Handle(sender as RadioButton);
      }
  
  
      void Handle(RadioButton radioButton)
      {
          bool flag = radioButton.IsChecked.Value;
  
          this.Title = "IsChecked = " + flag.ToString();
  
      }
  
      public class RadioConverter : IValueConverter
      {
          public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
          {
              return !(bool)parameter;
          }
  
          public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
          {
              return !(bool)value ? parameter : null;
          }
  
      }
  </code></pre>