Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

How to implement a custom MarkupExtension?

Back to Forum: Tech Off
  • User profile image

    Hi everybody

    I want implement a custom MarkupExtension class to extend XAML in Avalon. I had implemented a class that inherit from System.Windows.Serialization.MarkupExtension, the code is similar as follows.

    using System.Windows.Serialization;
    namespace MarkupExtensionNS
        public class MyMarkupExtension : MarkupExtension
            public MyMarkupExtension()

            public override object ProvideValue(object targetObject, object
                return "OK";

    After, I use follows XAML code to reference my markup extension.

    <?Mapping XmlNamespace="CodeMapNS" ClrNamespace="MarkupExtensionNS" ?>
    <Window x:Class="MarkupExtensionNS.Window1"
            <TextBlock TextContent="{c:MyMarkupExtension}"/>

    But I got a compiler error as follows.

    MS.Internal.Markup.XamlParseException: The value '{c:MyMarkupExtension}' is
    not a valid MarkupExtension expression. Could not resolve
    'MyMarkupExtension' in namespace 'CodeMapNS'. 'MyMarkupExtension' must be a
    subclass of MarkupExtension. Line 9 Position 14.


    I had try to move MyMarkupExtension to a new assembly and The original assembly that include the XAML file reference to the new assembly that include the declaration of MyMarkupExtension. But the compiler error is exist always.

    Who can help me?

  • User profile image

    Hmm...  I've had this working just fine in Beta1 RC1, but I tried it again now in Beta 1, and I can't get it to work!  I wonder if they changed something...

  • User profile image

    Are you implement custom MarkupExtension in Beta1 RC1? Can you send the source code to me? My MarkupExtension can not working right in Bata1 RC1.

    Thanks a lot.

    I'm Chinese. My English is vary poor. So please help me more. Thanks so much.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.