On my Control is a TreeView with a set of Items which can be in one of three levels. The Objects inside the TreeView have a property called Level which determines this. Under the TreeView there are some TextBoxes. The TextBoxes should be filled depending on the level of the SelectedItem in the TreeView. If an Item on the top level is selected only the first TextBox should be filled. If an item on the second level is selected the first an second TextBox should be filled and so on. This is the structure of items in the TreeView:
-Item1 <- Level = 0
-- SubItem1 <- Level = 1
-- SubSubItem1 <- Level = 2
-- SubSubItem2
-Item2 <- Level = 0
-- SubItem1 <- Level = 1
-- SubSubItem1 <- Level = 2
-- SubItem2
-- SubSubItem1
I have tried to acomplish this task with a trigger in both, the HierarchicalDataTemplate of the TreeView and the style of the TextBox. The problem with the HierarchicalDataTemplate of the TreeView is, that I have no access on the TextBox since it (the TextBox) is not in the scope of the DataTemplate and does not compile. The other attempt simply doesn't produce a result. This is the XAML of my control:
<TreeView Grid.Row="1" Margin="5" ItemsSource="{Binding Privileges}" Name="Privileges">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Items}">
<TextBlock Text="{Binding}"/>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
<TextBox Grid.Row="0" Margin="3">
<TextBox.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Privileges.SelectedItem.Level}" Value="0">
<Setter Property="TextBox.Text" Value="Test"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>