0

In WPF I try to use databinding to define the BindingMode.

<controls:BoolToStringConverter x:Key="BoolToStringConverter" FalseValue="OneWay" TrueValue="TwoWay" />
<TextBox Text="{Binding MyText, Mode="{Binding Path=IsWriteable, Converter={StaticResource BoolToStringConverter}}" />

also, I've tried with a System.Windows.Data.BindingMode enum as datatype of property "MyBindingMode" and bind to this, but it isn't working either

<TextBox Text="{Binding MyText, Mode={Binding Path=MyBindingMode}}" />

Is there any possibility for such a binding or what is an appropriate approach to achieve this?

Edit:

actually in my context it's not an TextBox, it is a DataGridTextColumn. I've tried to bind IsReadOnly="{Binding IsOnlyReadable}" but that has no effect on the DataGridTextColumn. Setting it fixed to IsReadOnly=True works but binding it to a constantly true property doesn't have this effect.

Finally it is solved and I've used this for the Binding of a DataGridColumn: https://stackoverflow.com/a/27465022/9758687

Coden
  • 2,579
  • 1
  • 18
  • 25
  • What are you trying to achieve? If you want to make the TextBox not accept input, bind IsWriteable to the IsReadOnly property of the Textbox `` – Lupu Silviu Jul 09 '18 at 08:09

1 Answers1

1

Take a look at this link. This seems to be what you are looking for: .Net v4 DataGridTextColumn.IsReadOnly seems to be faulty

And this is the code that might fix your problem:

  <DataGridTextColumn>  
   <DataGridTextColumn.CellStyle>
   <Style>
     <Setter Property="UIElement.IsEnabled" Value="{Binding IsOnlyReadable}" />
   </Style>
  </DataGridTextColumn.CellStyle>
 </DataGridTextColumn>
Lupu Silviu
  • 1,145
  • 11
  • 23
  • Thanks, that was the trick. Finally i used this one: https://stackoverflow.com/a/27465022/9758687 – Coden Jul 09 '18 at 10:00