Search code examples
wpfvisual-studio-2010spacemarkup-extensions

WPF : Space key problem when using a Custom Markup Extension in VS2010


We developed a localization solution using custom markup extension in VS 2008.

At the time, we used it this way :

<TextBlock Text={utilsWpf:Intl Key=ObjectName.PropertyName, DefaultText=Default Name} />

(Notice the space in the DefaultText). (Notice also how the text-color tool of StackOverflow changes the color of the words as well).

But it works fine and compiles without a problem.

In VS 2010 though, whenever you try to type a space using this way of implementing a markup extension, the IDE always adds a comma for you, which gives :

<TextBlock Text={utilsWpf:Intl Key=ObjectName.PropertyName, DefaultText=Default, Name} />

Of course, it doesn't compile anymore...

One solution to it is to implement this markup extension the other way :

<TextBlock>
    <TextBlock.Text>
       <utilsWpf:Intl Key="ObjectName.PropertyName", DefaultText="Default Name"/>
    </TextBlock.Text>
</TextBlock>

But it adds a lot of lines and we don't have only one textblock as you can imagine...

Another solution is not to type the space, but copy another space and paste it (which still compiles in VS 2010 but is quite crude).

As I see it, our solution isn't the best practice.

What kind of best practice would you advise to be able to type spaces without inconvenience?

Thanks for your insights.


Solution

  • Try using single quotes:

    <TextBlock Text="{utilsWpf:Intl Key=ObjectName.PropertyName, DefaultText='Default Name'}" />