AttachedCommandBehavior V2を使用して、ダブルクリックなどのListBoxItemイベントをビューモデルに対して実行されるコマンドに変換しようとしています。スタイルを使用して複数のAttachedCommandBehaviorsを適用する
私はこれは私がエミュレートしようとしているサンプルコードで、複数のイベントのためのコマンドを起動します:
<Border Background="Yellow" Width="350" Margin="0,0,10,0" Height="35" CornerRadius="2" x:Name="test">
<local:CommandBehaviorCollection.Behaviors>
<local:BehaviorBinding Event="MouseLeftButtonDown" Action="{Binding DoSomething}" CommandParameter="An Action on MouseLeftButtonDown"/>
<local:BehaviorBinding Event="MouseRightButtonDown" Command="{Binding SomeCommand}" CommandParameter="A Command on MouseRightButtonDown"/>
</local:CommandBehaviorCollection.Behaviors>
<TextBlock Text="MouseDown on this border to execute the command"/>
</Border>
私はListBoxItemにそれを適用したいので、私はスタイルを通してそれをやろうとしています実行して:私はそれがCOMP、その後BehaviorBindingsの1をコメントアウト場合
<ListBox.ItemContainerStyle>
<Style>
<Setter Property="acb:CommandBehaviorCollection.Behaviors">
<Setter.Value>
<acb:CommandBehaviorCollection>
<acb:BehaviorBinding Event="MouseDoubleClick" Command="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBox}}" CommandParameter="{Binding}"/>
<acb:BehaviorBinding Event="KeyUp" Command="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBox}}" CommandParameter="{Binding}"/>
</acb:CommandBehaviorCollection>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
をしかし、私はerror MC3089: The object 'CommandBehaviorCollection' already has a child and cannot add 'BehaviorBinding'. 'CommandBehaviorCollection' can accept only one child. Line 39 Position 11.
も言うことコードでコンパイルエラーを取得しますileが実行時のxamlロード例外 "値はnullにすることはできません。パラメータ名:プロパティ」ので、私は、私も正しいアプローチを取っているかはわからない
誰でもListBoxItem上に複数の動作バインディングを設定するには、正しい構文の例を提供することができます
[関連する質問](http://stackoverflow.com/questions/1035023/firing-a-double-click-event-from-a-wpf-listview-item-using-mvvm)スタイルを使用して1つのCommandBehaviorのみを設定する例 – BrandonAGr
見つかった記事に記載されているように2つの対話トリガを試しましたか?それが私が提案しようとしていたものです。 – Phil