VS2010 Custom MarkupExtension
Asked Answered
B

1

26

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?

Biologist answered 28/4, 2010 at 21:26 Comment(2)
Have you tried this in Blend? I'm wondering if Cyder (the VS20120 XAML Designer) it's simply not able to deal with Custom Markup Extensions. It wouldn't surprise me since it's quite sensitive, although this is a basic one. Does this error crashes the designer or it works and it's just shown as an error?Jerome
Did you already find a solution?Postpone
C
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.

Chromogenic answered 18/2, 2013 at 21:39 Comment(1)
Could you provide some code snippet how you solved this problem?Postpone

© 2022 - 2024 — McMap. All rights reserved.