I’ve downloaded this AttachedCommandProject and ran it and it works well, enables me to e.g. put a MouseDown command on a Border element and handle that with a command in my ViewModel.
Now I would like to add this AttachedCommand functionality to my MVVM Visual Studio Template.
I copied all the necessary files into the my Commands folder of the MVVM project:
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
But when I try to use it with the same syntax as in the original project, I get the error The property ‘CommandBehavior.Event’ does not exist in XML namespace ‘clr-namespace:MvvmWithAttachedBehaviors.Commands’..
There are no other files to copy and no other references to add as far as I can see.
What could this error be trying to tell me? Has anyone gotten this AttachedCommandBehavior functionality to work in other projects?
<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>
Did the source files that contain
CommandBehaviorget copied into the new project? If so, I would check the namespace they are in. It could be that the namespace is different in this project. The line: {xmlns:c="clr-namespace:MvvmWithAttachedBehaviors.Commands"} is setting the prefix “c” to represent a namespace calledMvvmWithAttachedBehaviors.Commandsthat exists in the local assembly. If this namespace is in a different assembly you will have to reference the assembly in this declaration.Have you tried rebuilding all? Sometimes the designer will give you xml namespace errors that clear up if you rebuild all.
I hope this helps a little…