1

このバインディングをプログラムで設定することはできません:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseLeftButtonDown">
        <i:InvokeCommandAction Command="{Binding Path=Document.MyDelegateCommandProperty}" />
    </i:EventTrigger>
</i:Interaction.Triggers>

私は試しました:

InvokeCommandAction ica = new InvokeCommandAction();
Binding actionCommandBinding = new Binding("Document.MyDelegateCommandProperty");
BindingOperations.SetBinding(ica, InvokeCommandAction.CommandProperty, actionCommandBinding);
System.Windows.Interactivity.EventTrigger eventTrigger = new System.Windows.Interactivity.EventTrigger("MouseLeftButtonDown");
eventTrigger.Actions.Add(ica);
eventTrigger.Attach(myUiElement);

誰でも助けることができますか?

4

3 に答える 3

0

コードで使用されることはありませんが、 BindingBindingクラスの MSDN の例によると、プロパティを設定する必要がありますBinding.Source

Binding actionCommandBinding = new Binding("Document.MyDelegateCommandProperty");
actionCommandBinding.Source = ......

stringソースオブジェクト/データコンテキストなしでコンストラクターを渡すだけです。

この投稿は役に立ちましたか?

于 2012-09-06T07:34:40.210 に答える