DadCat93
DadCat93

Reputation: 11

Binding TextBox IsEnabled to property of VM

Here's the sanitized control hierarchy in my View, and its bindings (I wish SO wouldn't remove leading spaces!!!)...

UserControl

StackPanel

ListView ItemsSource="{Binding LineItems}" SelectedItem="{Binding SelectedLineItem}"

GridView

GridViewColumn

GridViewColumn.CellTemplate

DataTemplate

TextBox Text="{Binding Description}"


LineItems and SelectedLineItem are properties in my ViewModel, while Description is a property within the class referenced by SelectedLineItem.

Now I need to enable/disable the TextBox based on a new "AllowEdit" property in my ViewModel (AllowEdit is NOT a propery of SelectedLineItem).

How do I bind the IsEnabled property of the TextBox to the AllowEdit property?

I've done the requisite reading, but it's not clear how to do this!

Thanks!

DadCat

Upvotes: 1

Views: 247

Answers (1)

Fede
Fede

Reputation: 44038

<TextBox IsEnabled="{Binding DataContext.AllowEdit, RelativeSource={RelativeSource AncestorType=ListView}}"/>

Upvotes: 2

Related Questions