この AttachedCommandProjectをダウンロードして実行したところ、うまく動作しました。たとえば、MouseDown コマンドを Border 要素に配置し、ViewModel のコマンドでそれを処理できます。
この AttachedCommand 機能をMVVM Visual Studio Templateに追加したいと思います。
必要なすべてのファイルを MVVM プロジェクトの my Commands フォルダーにコピーしました。
13.12.2008 21:00 7.445 BehaviorBinding.cs
05.12.2008 17:50 7.477 CommandBehavior.cs
13.12.2008 21:01 3.908 CommandBehaviorBinding.cs
13.12.2008 21:06 5.097 CommandBehaviorCollection.cs
04.12.2008 21:48 3.564 EventHandlerGenerator.cs
05.12.2008 17:52 2.376 ExecutionStrategy.cs
05.12.2008 17:52 2.067 SimpleCommand.cs
しかし、元のプロジェクトと同じ構文で使用しようとすると、The property 'CommandBehavior.Event' does not exist in XML namespace 'clr-namespace:MvvmWithAttachedBehaviors.Commands'. というエラーが表示されます。.
私が見る限り、コピーするファイルや追加する参照は他にありません。
このエラーは何を伝えようとしているのでしょうか? この AttachedCommandBehavior 機能を他のプロジェクトで使用できるようになった人はいますか?
<Window x:Class="MvvmWithAttachedBehaviors.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:MvvmWithAttachedBehaviors.Commands"
Title="Main Window" Height="400" Width="800">
<DockPanel>
<StackPanel>
<TextBlock Text="{Binding Output}"/>
<Border Background="Yellow" Width="350" Margin="0,0,10,0" Height="35" CornerRadius="2"
c:CommandBehavior.Event="MouseDown"
c:CommandBehavior.Command="{Binding SomeCommand}"
c:CommandBehavior.CommandParameter="This is the parameter sent."
>
<TextBlock Text="MouseDown on this border to execute the command"/>
</Border>
</StackPanel>
</DockPanel>
</Window>