2009-05-29 21 views
0

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> 

Répondre

1

Est-ce que les fichiers sources qui contiennent CommandBehavior sont copiés dans le nouveau projet? Si oui, je vérifierais l'espace de noms dans lequel ils se trouvent. Il se pourrait que l'espace de noms soit différent dans ce projet. La ligne: {xmlns:c="clr-namespace:MvvmWithAttachedBehaviors.Commands"} définit le préfixe "c" pour représenter un espace de noms appelé MvvmWithAttachedBehaviors.Commands qui existe dans l'assembly local. Si cet espace de noms est dans un assembly différent, vous devrez référencer l'assembly dans cette déclaration.

Avez-vous essayé de tout reconstruire? Parfois, le concepteur vous donnera des erreurs d'espace de noms XML qui disparaîtront si vous reconstruisez tout.

J'espère que cela aide un peu ...

+0

C'est ce que je vis à vis, a dû changer "namespace AttachedCommandBehavior" à "namespace MvvmWithAttachedBehaviors.Commands", merci. –

0

Vous avez à faire référence à la AttachedCommandBehavior.dll de montage dans votre projet, et modifier la déclaration d'espace de noms XAML comme ça:

xmlns:c="clr-namespace:AttachedCommandBehavior;assembly=AttachedCommandBehavior"