2009-05-29 38 views
0

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

回答

1

是否將包含CommandBehavior的源文件複製到新項目中?如果是這樣,我會檢查它們所在的命名空間。這可能是該項目中的名稱空間不同。行:{xmlns:c="clr-namespace:MvvmWithAttachedBehaviors.Commands"}正在設置前綴「c」以表示名爲MvvmWithAttachedBehaviors.Commands的名稱空間,該名稱空間存在於本地程序集中。如果該名稱空間位於不同的裝配中,則必須在此聲明中引用該裝配。

你試過重建所有的東西嗎?有時候,如果你重建所有的東西,設計者會給你xml命名空間的錯誤。

我希望這有助於有點...

+0

這就是我忽略了,必須將「命名空間AttachedCommandBehavior」更改爲「命名空間MvvmWithAttachedBehaviors.Commands」,謝謝。 – 2009-05-29 13:43:30

0

你要引用的程序集AttachedCommandBehavior.dll在您的項目,並修改XAML命名空間聲明這樣的:

xmlns:c="clr-namespace:AttachedCommandBehavior;assembly=AttachedCommandBehavior" 
相關問題