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にあり、上記の例はごくわずかです。「追加」は、で選択されたものに基づいてButton、ViewModelに新しい子を追加します。そして、可視性は、のSelectedItemのいくつかのプロパティに応じて変化します。TreeViewComboBoxTextBoxComboBox

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 に答える