J'ai téléchargé this AttachedCommandProject et l'ai couru et fonctionne bien, me permet de par exemple. mettre une commande MouseDown sur un élément Border et gérer cela avec une commande dans mon ViewModel.Comment utiliser AttachedCommandBehavior dans un nouveau projet?
Maintenant, je voudrais ajouter cette fonctionnalité AttachedCommand à mon MVVM Visual Studio Template.
J'ai copié tous les fichiers nécessaires dans le dossier Mes commandes du projet 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
Mais lorsque je tente de l'utiliser avec la même syntaxe que dans le projet initial, je reçois l'erreur Le La propriété 'CommandBehavior.Event' n'existe pas dans l'espace de noms XML 'clr-namespace: MvvmWithAttachedBehaviors.Commands'..
aucun autre fichier à copier et aucune autre référence à ajouter aussi loin que je peux voir.
Qu'est-ce que cette erreur pourrait vouloir dire? Quelqu'un at-il obtenu cette fonctionnalité AttachedCommandBehavior pour travailler dans d'autres projets?
<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>
C'est ce que je vis à vis, a dû changer "namespace AttachedCommandBehavior" à "namespace MvvmWithAttachedBehaviors.Commands", merci. –