VS2010 自定义标记扩展 [英] VS2010 Custom MarkupExtension
问题描述
我们刚刚从vs2008切换到vs2010,我们的项目编译运行良好,没有任何问题.但是,xaml 设计器有一些错误.这是错误之一,希望有人能提供解决方案.
We have just switched to vs2010 from vs2008, and our projects compile and run well without any problem. However, the xaml designer has some errors. Here is one of the errors hope someone can provide a solution.
我们有一个自定义的 MarkupExtension,我们在 xaml 中使用它来获取某些资源.像这样:
We have a custom MarkupExtension, and we use it in xaml to get certain resources. Something like this:
我知道我们可以使用 StaticResource 或 DynamicResource.但是,我们有理由使用自定义标记扩展.
I know we can use StaticResource or DynamicResource. However we have our reasons to use the custom markupextension.
来自设计者的错误信息是:
The error message from the designer is:
'GetResourceExtension' 对 Setter.Value 无效.唯一的支持的 MarkupExtension 类型是 DynamicResourceExtension
和BindingBase
或派生类型.
'GetResourceExtension' is not valid for Setter.Value. The only supported MarkupExtension types are
DynamicResourceExtension
andBindingBase
or derived types.
我的问题是代码在vs2008中运行良好,在2010中也运行良好,如何让2010的设计器工作?
My question is that the code works fine in vs2008, and also runs fine in 2010, how to make the 2010 designer work?
推荐答案
我已经编写了一些标记扩展,虽然代码可以运行,但我遇到的 Xaml 错误就像你一直遇到的那样.假设您有有效的代码,我发现消除错误的唯一方法是通过重建选项,然后运行应用程序.
I've written a few Markup Extensions and although the code runs I get Xaml Error's like the one you get all the time. Assuming you have valid code I found the only way to get rid of the errors was via the rebuild option and then running the app.
当然,问题是如果您再次更改或移动它,错误似乎又回来了.我的假设是静态编译无法完全解决您的标记所做的任何事情,并且会基于此抛出错误.
Of course the problem is if you change it again or move it the errors seem to come back. My assumption is the static compile cannot fully resolve whatever your markup is doing and is throwing the error based on this.
在我的例子中,我正在编写一个方法绑定器,因为在运行时对象为空,我最终不得不使用 new Object();并在运行时将其换出.这很hacky,但编译错误让我发疯.
In my case I was writing a method binder and because the object was null until runtime I ended up having to use new Object(); and swapping it out at runtime. It's hacky but the compile error were driving me nuts.
xaml 解析器在 2012 年似乎更好,但即便如此,仍然存在奇怪的错误.
The xaml parser seems to be better in 2012 but even then there are the odd errors.
这篇关于VS2010 自定义标记扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!