我已经下载this AttachedCommandProject并运行它,它很好运行,使我能够例如将一个MouseDown命令放在一个Border元素上,并使用我的ViewModel中的命令处理该命令。如何在新项目中使用AttachedCommandBehavior?
现在我想添加此附加命令功能到我的MVVM Visual Studio Template。
我复制了所有必需的文件到MVVM项目的我的命令文件夹:
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
但是,当我尝试使用相同的语法使用它作为在原项目中,我得到的错误的属性'CommandBehavior.Event'在XML命名空间'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>
这就是我忽略了,必须将“命名空间AttachedCommandBehavior”更改为“命名空间MvvmWithAttachedBehaviors.Commands”,谢谢。 – 2009-05-29 13:43:30