3

I need to dynamically create some TreeViewItems, each of them needs to have a Command bind to DoubleClick Mouse Action. The problem is that i want to pass a parameter to this Command, but I don't know how to do it.

Currently code:

    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;
    }

I usually set in XAML in this way:

    CommandParameter="{Binding Path=SelectedItem, ElementName=MainTV}"

How to set dynamically in code?

1 Answer 1

3

Solved the mystery!
I don't really know why, but InputBinding.CommandParameterProperty is available only since .NET framework 4.0. I was working with 3.0 so I was unable to bind the CommandParameter in code.
If anyone knows how to bypass this, it will be very helpful.

https://msdn.microsoft.com/it-it/library/system.windows.input.inputbinding.commandparameterproperty(v=vs.100).aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.