I am trying to create my own MarkupExtension for localization. The idea is to pass a name of a resource (for example 'Save') to the markup extension and the return would be localized value (for example 'Save' in en-US, 'Speichern' in de-de and so on).
This works pretty good, but I am unable to make it work with intellisense.
This is my simplified MarkupExtension class:
public class MyMarkupExtension : MarkupExtension
{
private readonly string _input;
public MyMarkupExtension(string input)
{
_input = input;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
// Here the actual value from the resources will be returned, for example for input 'Save':
// 'Save' for Thread.CurrentThread.CurrentUICulture="en-US"
// 'Speichern' for Thread.CurrentThread.CurrentUICulture="de-de"
// ...
return Resources.ResourceManager.GetString(_input);
}
}
And xaml:
<TextBox Text="{m:MyMarkup Save}"></TextBox> <!-- No Intellisense, but it works. -->
<TextBox Text="{m:MyMarkup {x:Static properties:Resources.Save}}"></TextBox> <!-- Intellisense works, but the input parameter for markup extension is already localized string -->
Any idea what to use in xaml so that the input to markup extension would be the literal string ('Save' in my example, which is a resource name, not a localized value) and that intellisense would work?
Text="{x:Static properties:Resources.Save}"
. This can be shortened a bit with some strategic naming, but the custom markup extension seems completely unnecessary. See my answer for details. Also, regardless of which solution you prefer, you should award someone the bounty before it expires. – Byway