WPF在代码中动态设置CommandParameter的绑定

3
我需要动态创建一些TreeViewItem,每个都需要绑定到双击鼠标操作的命令。问题是我想向该命令传递一个参数,但我不知道该如何实现。
当前代码:
    private void AddExecuted(object sender, ExecutedRoutedEventArgs e)
    {
        MyTreeViewItem T = new MyTreeViewItem();

        InputBinding IB = new InputBinding(RenameCommand, new MouseGesture(MouseAction.LeftDoubleClick));
        Binding B = new Binding("SelectedItem");
        B.Source = MainTV;

        //BindingOperations.SetBinding(IB, IB.CommandParameterProperty /*CommandParameterProperty  does not exist*/, B);

        T.InputBindings.Add(IB);

        MainTV.Items.Add(T);            

        e.Handled = true;
    }

我通常用以下方式在XAML中设置:
    CommandParameter="{Binding Path=SelectedItem, ElementName=MainTV}"

如何在代码中动态设置?
1个回答

3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接