VS2010 Custom MarkupExtension

◇◆丶佛笑我妖孽 提交于 2019-12-04 15:18:48

问题


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.

We have a custom MarkupExtension, and we use it in xaml to get certain resources. Something like this:

<Button Style="{l:GetResource Key=MyButtonStyle}" />

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' is not valid for Setter.Value. The only supported MarkupExtension types are DynamicResourceExtension and BindingBase or derived types.

My question is that the code works fine in vs2008, and also runs fine in 2010, how to make the 2010 designer work?


回答1:


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.

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.

The xaml parser seems to be better in 2012 but even then there are the odd errors.



来源:https://stackoverflow.com/questions/2733257/vs2010-custom-markupextension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!