如何使用连接的CommandBehavior在一个新的项目?
-
06-09-2019 - |
题
我已经下载这AttachedCommandProject 并运行它,它的效果很好后,使我如一个边框元件上放一个的MouseDown命令和处理与在我的视图模型的命令。
现在我想为添加此功能AttachedCommand ,以我的 MVVM的Visual Studio模板。
我复制了所有必需的文件到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的命名空间: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>
解决方案
这是否包含源文件CommandBehavior
被复制到新项目?如果是的话,我会检查他们的命名空间。这可能是因为该命名空间是在这个项目中的不同。行:{xmlns:c="clr-namespace:MvvmWithAttachedBehaviors.Commands"
}是设置前缀“C”来表示存在于本地组件的命名空间称为MvvmWithAttachedBehaviors.Commands
。如果该名称空间是在不同的组件,你将不得不引用组件在此声明。
你试过重建呢?有时候,设计师会给您,如果您重建全部清理XML命名空间的错误。
我希望这有助于有点...
其他提示
您必须引用您的项目中装配AttachedCommandBehavior.dll,并修改这样的XAML命名空间声明:
xmlns:c="clr-namespace:AttachedCommandBehavior;assembly=AttachedCommandBehavior"
不隶属于 StackOverflow