views:

13

answers:

0

Hello.
I have created a custom MarkupExtension for localization like below:

[System.Windows.Markup.MarkupExtensionReturnType(typeof(string))]
[System.Windows.Markup.ContentProperty("LocalizedValue")]
public class LocItem : System.Windows.Markup.MarkupExtension
{
    public LocItem()
        :base()
    {
    }

    public string LocalizedValue { get; set; }

    // other useful fields...
}

Then I have created a ResourceDictionary which contains LocItem objects whose content is going to be localized.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ltl="clr-namespace:LocTranslate;assembly=LocTranslateLibrary">

<ltl:LocItem x:Key="loc_fileName">File name:</ltl:LocItem>

<!-- Other LocItem objects ... -->

</ResourceDictionary>

In the main program I reference the object using DynamicResource markup extension.

<TextBlock Text="{DynamicResource loc_fileName}" />

If I use it in a property of type "object" (e.g. "Content" property) there is no problem. But if I use it in the Text property of a TextBlock, like the example above, the designer raises the following exception: "InstanceBuilderException: An object of the type "LocTranslate.LocItem" cannot be applied to a property that expects the type "System.String"."

I have signed the markup extension with "[System.Windows.Markup.MarkupExtensionReturnType(typeof(string))]" attribute, so it should work. Of course the project compiles and runs successfully, but I can't use the VS designer. Is this a known bug of VS 2010?