我阅读了以下有关VS2013中可用的新xaml编辑功能的博客文章:
数据绑定Intellisense是我多年来一直想要的东西,因此我尝试了一下-但不幸的是,它在错误列表中返回了一个错误(尽管它仍然可以正常运行)。
这是我添加到UserControl声明/标签中的内容:
d:DataContext="{d:DesignInstance Type=lTemplates:TemplateEditorCustomVM}"
这是列表中的错误:
错误95访问被拒绝:
System.Collections.ObjectModel.ObservableCollection'1[_.di1.TemplateEditorCustomVM+TemplateCriteriaVM]'.
我不太确定它要做什么,两个类都声明为public(主视图模型和嵌套类)。
任何人有任何想法吗?
如果不是这样,这不是世界末日,因为Resource Key Intellisense似乎可以正常工作,但这仍然是一笔不小的数目。
编辑
好的-我将嵌套的类移到了公共名称空间,而VS给了我一个更详细的错误:
错误64
Attempt by method '_.di1.Templates.TemplateEditorCustomVM..ctor()' to access method 'System.ComponentModel.BindingList'1<System.__Canon>..ctor()'
失败。
我有点困惑,我必须说:
首先,为什么intellisense需要实例化VM类,它所关心的只是可用的属性和属性的类型-所有这些都可以通过反射来检索。
其次,我不明白为什么在启动应用程序时它在正常运行时会出错。
我可能不得不做旧的技巧,即让Visual Studio调试自身来运行设计器,以查看其要执行的操作...
进一步编辑
正确,我将BindingList属性更改为直接的List属性(因为BindingList是从WinForms的角度来看的,因此我认为这可能值得更改以查看其功能)。但是我遇到了类似的错误:
错误64
Attempt by method '_.di3.Templates.TemplateEditorCustomVM..ctor()' to access method 'System.Collections.Generic.List'1<System.__Canon>..ctor()' failed.
我在System .__ Canon上做了一个快速的google,它只是一个优化细节:
https://stackoverflow.com/a/16856205/182568
尽管仍无法猜测到底发生了什么,但是嗯,我会继续深入研究。
编辑-现在有一个回购
正确,我开始注释掉VM的巨大块,以求出于好奇而深入研究-现在,我有了一个VM类,该类似乎可以重现此问题:
public class Nested
{
public class TestCheck
{
public int One { get; set; }
public int Two { get; set; }
}
}
public class SanityTestVM
{
public List<Nested.TestCheck> Test { get; set; }
}
给出:
错误14尝试使用方法
'_.di14.Templates.SanityTestVM..ctor()' to access method 'System.Collections.Generic.List'1<System.__Canon>..ctor()' failed.
似乎问题在于列表具有其类型的嵌套类-如果它是普通类(非嵌套),则一切正常。
我想我需要为此提交连接案例-在我能确认这一点之前,我在Windows 8.1机器上有4个版本的VS,我只想排除开发环境。
看起来这确实是VS2013中的错误-我已经请了一些同事看看他们是否可以复制它,并且可以复制,所以这不仅仅是我的环境。
我已经提交了一个连接案例-因此,如果有人遇到此错误,请随时对其进行投票:
https://connect.microsoft.com/VisualStudio/feedback/details/808323/
该问题是由于视图模型包含一个属性而该属性具有一个包含嵌套类类型的通用定义而导致的:
public class AClass
{
public class AnotherClass
{
public int AProperty { get; set; }
}
}
class TestVM
{
public List<AClass.AnotherClass> NestedTypeList { get; set; }
}
XAML:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:TestVM}"
Title="MainWindow" Height="354" Width="535">
<Grid>
</Grid>
</Window>
给出:
Error 1 Attempt by method '_.di1.WpfApplication1.TestVM..ctor()' to access method 'System.Collections.Generic.List'1<System.__Canon>..ctor()' failed.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句