3

いくつかのTreeViewItemを動的に作成する必要があります。各アイテムには、DoubleClickMouseActionにコマンドをバインドする必要があります。問題は、このコマンドにパラメーターを渡したいのですが、その方法がわかりません。

現在のコード:

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

コードで動的に設定するにはどうすればよいですか?

4

1 に答える 1

3

謎を解いた!
理由はよくわかりませんが、InputBinding.CommandParameterPropertyは.NETFramework4.0以降でのみ使用できます。3.0で作業していたため、コードでCommandParameterをバインドできませんでした。
誰かがこれを回避する方法を知っているなら、それは非常に役に立ちます。

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

于 2013-02-20T08:30:30.203 に答える