Mar*_*lon 5 c# wpf intellisense xaml visual-studio
我阅读了以下有关VS2013中新的xaml编辑功能的博文:
数据绑定智能感知是我多年来一直想要的东西,所以我试了一下 - 但遗憾的是它在错误列表中返回了一个错误(虽然它仍然很好).
这是我添加到UserControl声明/标签中的内容:
d:DataContext="{d:DesignInstance Type=lTemplates:TemplateEditorCustomVM}"
Run Code Online (Sandbox Code Playgroud)
这是列表中的错误:
错误95访问被拒绝:
System.Collections.ObjectModel.ObservableCollection'1[_.di1.TemplateEditorCustomVM+TemplateCriteriaVM]'.
我不完全确定它正在尝试做什么,这两个类都被声明为public(主视图模型和嵌套类).
有人有任何想法吗?
如果不是,它不是世界末日,因为资源密钥智能感知似乎工作,这仍然是一个巨大的奖金.
编辑
好的 - 我将嵌套的类移到公共名称空间中,VS给了我一个更详细的错误:
错误64
Attempt by method '_.di1.Templates.TemplateEditorCustomVM..ctor()' to access method 'System.ComponentModel.BindingList'1<System.__Canon>..ctor()'失败.
我必须说:我有点困惑:
首先,为什么intellisense需要实例化VM类,它应该关心的是什么属性可用以及它们是什么类型 - 所有这些都可以通过反射来检索.
其次,我不明白为什么它在应用程序启动时运行良好时出错.
我可能不得不做一个让视觉工作室调试本身运行设计师的老技巧,看看它正在尝试做什么......
进一步编辑
是的,我将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上做了一个快速谷歌,它只是一个优化细节:
虽然仍然没有接近发生什么事情,但是我会继续深入挖掘.
编辑 - 现在有一个回购
是的,我开始评论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; }
}
Run Code Online (Sandbox Code Playgroud)
得到:
错误14尝试方法
'_.di14.Templates.SanityTestVM..ctor()' to access method 'System.Collections.Generic.List'1<System.__Canon>..ctor()' failed.
似乎问题是有一个List,它的类型有一个嵌套类 - 如果它是一个普通类(非嵌套),一切都很好.
我想我需要为此提交一个连接案例 - 在我做之前有人能够确认这一点,我在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; }
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
给出:
Error 1 Attempt by method '_.di1.WpfApplication1.TestVM..ctor()' to access method 'System.Collections.Generic.List'1<System.__Canon>..ctor()' failed.
| 归档时间: |
|
| 查看次数: |
934 次 |
| 最近记录: |