0

我想在同一个 TreeViewItemContainer中绑定一个TextBox基于 SelectedItem的 Visibility。ComboBox我想我可以使用转换器进行绑定,但我不知道如何将ComboBox项目作为TextBox绑定的参数发送。这可以做到吗?

<TreeView>
    <TreeView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <ComboBox Margin="2,0" Name="SkillSelectCB" ItemsSource="{Binding PotentialChildren}" />
                <TextBox Margin="2,0" Width="50" Visibility="{Binding ??}" />
                <Button Margin="2,0" Content="Add" />
            </StackPanel>
        </DataTemplate>
    </TreeView.ItemTemplate>
</TreeView>

这实际上是在 HierarchicalDataTemplate 中,上面的示例非常少。“添加”ButtonTreeView根据在ComboBox. 可见性TextBox会根据ComboBoxSelectedItem 的某些属性而改变。

4

1 回答 1

0

所以 Xaml 的TextBox

<TextBox Margin="2,0"Width="50" Visibility="{Binding SelectedItem, ElementName=SkillSelectCB, Converter={StaticResource SkillToVisibilityConverter}}" />

和转换器:

public class SkillToVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var s = (Skill)value;
        return (s == null || !s.Specialized) ? "Hidden" : "Visible";
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
于 2013-02-28T16:32:12.530 回答