听起来您正在尝试TreeView.ItemsSource
根据某些ListBox
.
如果是这种情况,DataTrigger
您应该EmployeeTree
根据TreeView.ItemsSource
或ListBox.SelectedItem
ListBox.SelectedIndex
<Style x:Key="EmployeeTreeStyle" TargetType="{x:Type TreeView}">
<!-- By default bind to MyListBox.SelectedItem.Leaves -->
<Setter Property="ItemsSource" Value="{Binding ElementName=MyListBox, Path=SelectedItem.Leaves}" />
<Style.Triggers>
<!-- If SelectedIndex = 0, bind to AllLeaves instead -->
<DataTrigger Binding="{Binding ElementName=MyListBox, Path=SelectedIndex}" Value="0">
<Setter Property="ItemsSource" Value="{Binding AllLeaves}" />
</DataTrigger>
</Style.Triggers>
</Style>
根据下面的评论更新
<Style x:Key="EmployeeTreeStyle" TargetType="{x:Type TreeView}">
<Style.Triggers>
<!-- Set ItemsSource based on which RadioButton is Selected -->
<DataTrigger Binding="{Binding ElementName=RadioButton1, Path=IsChecked}" Value="True">
<Setter Property="ItemsSource" Value="{Binding AllLeaves}" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=RadioButton2, Path=IsChecked}" Value="True">
<Setter Property="ItemsSource" Value="{Binding ElementName=RadioButton2, Path=DataContext.Leaves}" />
</DataTrigger>
</Style.Triggers>
</Style>