我已經下載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