Using MVVM style I have successfully bound an ObservableCollection<string> to a ListBox, showing up the values as RadioButtons. The control behaves exactly as expected.
Now I have an issue regarding some TextBoxes bound to this ListBox: I want whenever the SelectedItem in the ListBox is equal to a specific value (e.g. ValueForEnabled) the TextBoxes to be enabled otherwise they should be disabled.
I know I have to bind to SeletedItem of the ListBox (named lbSource) but how exactly is this done?
I want something like this (Pseudo code):
<TextBox ...
IsEnabled="{Binding ElementName=lbSource, Path=SelectedItem='ValueForEnabled',
Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
...
/>
OK! Solved it (in another way) myself! For anyone who wants to know:
<TextBox
...
usual property definitions
...
>
<TextBox.Style>
<Style>
<Setter Property="TextBox.IsEnabled" Value="False"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=lbSource , Path=SelectedItem}" Value="ValueForEnabled">
<Setter Property="TextBox.IsEnabled" Value="true"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With