I want to use a data trigger in a text box to set the isEnabled property according to the value of a property of the selected item in a data grid.
I am trying this:
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<DataTrigger Binding="{Binding MyDataGridName, ElementName=SelectedItem.MyProperty1.MyProperty2}" Value="1">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
But the textBox is always enabled. I check that really when I select the item, it has property1 and property2 has 1 as value. So I guess that the problem is that I don't set the trigger correctly.
try this code, you need to specify the Datagrid as elementName not the selectedItem:
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MyDataGridName, Path=SelectedItem.MyProperty1.MyProperty2}" Value="1">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>