Xamarin.android MvvmCross vNext:在未引用的程序集中定义了ObservableCollection
我现在要构建我的PCL模型,这花费了一些时间制作插件,但是现在在我的Android UI项目中,我在构建它时遇到了两个错误 第一个错误是:Xamarin.android MvvmCross vNext:在未引用的程序集中定义了ObservableCollection,xamarin.android,portable-class-library,mvvmcross,Xamarin.android,Portable Class Library,Mvvmcross,我现在要构建我的PCL模型,这花费了一些时间制作插件,但是现在在我的Android UI项目中,我在构建它时遇到了两个错误 第一个错误是: The type 'System.Collections.ObjectModel.ObservableCollection`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows, V
The type 'System.Collections.ObjectModel.ObservableCollection`1<T0>' is defined in an assembly that is not referenced.
You must add a reference to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e,
Retargetable=Yes'. C:\ENM\Main\src\prod\Mobile\Stakeholder\UI.Android.vNext\Views\LocationsMapView.cs 40 32 UI.Android.vNext
foreach statement cannot operate on variables of type
'System.Collections.ObjectModel.ObservableCollection`1<BK.EMS.Stakeholder.Model.ViewModels.LocationViewModel>'
because 'System.Collections.ObjectModel.ObservableCollection`1<BK.EMS.Stakeholder.Model.ViewModels.LocationViewModel>'
does not contain a public definition for 'GetEnumerator'
C:\ENM\Main\src\prod\Mobile\Stakeholder\UI.Android.vNext\Views\LocationsMapView.cs 40 32 UI.Android.vNext
my ViewModel中的Locations
属性如下所示:
public ObservableCollection<LocationViewModel> Locations
{
get { return _locations; }
set
{
_locations = value;
RaisePropertyChanged(() => Locations);
}
}
公共可观测采集位置
{
获取{return\u locations;}
设置
{
_地点=价值;
RaisePropertyChanged(()=>位置);
}
}
没有什么太复杂,在非PCL模型中工作良好
那么我该如何解决这个问题呢?更新:请参阅其他答案。看来我们现在有了解决这个问题的办法
我相信这与这个问题有关- 链接到: 这是Xamarin提出的一个错误:和 恐怕我现在不了解推荐的强签名解决方案 请更新错误报告以提醒Microsoft PCL和Xamarin团队这一点。微软和Xamarin团队正在就此进行交流(尽管是通过我!),我希望我们能找到一种方法,让微软或Xamarin发布一些已签名的DLL
同时,一些可能的解决办法是:
查看您的示例代码,我只想尝试:
private ObservableCollection<LocationViewModel> _locations;
public IEnumerable<LocationViewModel> Locations
{
get { return _locations; }
set
{
if (value != null && !(value is ObservableCollection<LocationViewModel>)
{
throw new Exception("You must Set an ObservableCollection");
}
_locations = (ObservableCollection<LocationViewModel>)value;
RaisePropertyChanged(() => Locations);
}
}
private observedcollection\u位置;
公共可数地点
{
获取{return\u locations;}
设置
{
if(value!=null&!(值为ObservableCollection)
{
抛出新异常(“必须设置ObservableCollection”);
}
_位置=(ObservableCollection)值;
RaisePropertyChanged(()=>位置);
}
}
然后,AddLocationOverlays
可以保持不变
唯一的问题是,如果你想在这个集合上绑定到INotifyCollectionChanged
,但我认为如果需要的话,你也可以找到解决方法,例如,你可以以某种方式公开另一个INotifyCollectionChanged钩子,或者你可以尝试使用涉及中间类库的黑客攻击
我承认,目前这些都是解决方法,而不是解决方案://我们现在有了解决此问题的方法-请参阅中Daniel Plaisted的修复
此修复在处签入,因为将
observateCollection
更改为IEnumerable
在setter中将不起作用,因为您无法将IEnumerable
转换为observateCollection
。您必须从IEnumerable
创建一个新的observateCollection
,如下所示:>新的ObservableCollection(ienum.ToList());
将等待一段时间,直到所有的初期问题得到解决。不过,我可能会在一旁玩一玩vNext,并在我的发现中报告。谢谢-问题已解决(假设您从未从UI端设置此问题-问题仍然存在!).不用担心你的选择。谢谢你的报道。
private ObservableCollection<LocationViewModel> _locations;
public IEnumerable<LocationViewModel> Locations
{
get { return _locations; }
set
{
if (value != null && !(value is ObservableCollection<LocationViewModel>)
{
throw new Exception("You must Set an ObservableCollection");
}
_locations = (ObservableCollection<LocationViewModel>)value;
RaisePropertyChanged(() => Locations);
}
}