我正在使用VS2013 Express。我是WPF和MVVM的新手。我已经使用NuGet将mvvmlight下载到我的项目中。我尝试使用GalaSoft_MvvmLight_Command:EventToCommand
。据我所知,我必须通过添加命名空间在xaml中添加引用:
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight"
但是,不幸的是我得到错误,说:
标签' EventToCommand'在XML命名空间中不存在 ' CLR-名称空间:GalaSoft.MvvmLight;装配= GalaSoft.MvvmLight'
我发现了一些信息,我必须包含GalaSoft.MvvmLight.WPF45
汇编,但我在包\ MvvmLightLibs.5.0.0.1 \ lib \文件夹中看不到这个dll。每个.NET版本都有许多文件夹,但每个程序集名称都相同,没有WPF45 sufix。发生了什么?我在哪里可以找到这个GalaSoft.MvvmLight.WPF45.dll程序集?或者在版本5中可能会对名称进行一些更改?
编辑:
使用对象浏览器,我发现EventToCommand
位于GalaSoft.MvvmLight.Command名称空间中的GalaSoft.MvvmLight.Platform程序集中。所以我做了
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
我现在可以编译项目了,但我仍然在xaml中遇到错误(这很奇怪):
类型' EventToCommand'的值无法添加到类型' TriggerActionCollection'
的集合或词典中
和
类型' EventToCommand'来自汇编' GalaSoft.MvvmLight.Platform'是使用旧版本的Blend SDK构建的,并且在Windows Presentation Framework 4项目中不受支持。
和xaml编辑器无法正确显示窗口(无效标记)。
Edit2:
在我将命名空间更改为xmlns:cmd="http://www.galasoft.ch/mvvmlight"
之后,我还将项目的目标框架从4.5更改为3.5。 IDE显示一个错误,关于几乎没有针对其他框架的NuGet包,所以我回到4.5 - 它现在神奇地工作;)。谢谢大家的帮助。
答案 0 :(得分:3)
如果您已经获得了4.0.0版,那么现在在XAML中如何完成它。击败1或更高:
的xmlns:CMD =" HTTP://www.galasoft.ch/mvvmlight"
我在这里的发布说明底部找到了这个:http://www.mvvmlight.net/installing/changes/
详细 Extras程序集中GalaSoft.MvvmLight.Command的XmlnsDefinitionAttribute
由于添加了XmlnsDefinitionAttribute,您可以简化在XAML中包含MVVM Light EventToCommand操作。见下面之前和之后:
在:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
x:Class="MvvmLight4.MainPage">
后:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
x:Class="MvvmLight4.MainPage">
答案 1 :(得分:0)
EventToCommand
存在于Extras
程序集中。
尝试:
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
更多信息:
要确定类所属的程序集,我通常转到定义,并在 [from metadata] 代码文件顶部的区域中引用程序集