Leon Bohmann
Leon Bohmann

Reputation: 402

Make intellisense recognize enums in XAML

So I have the following setup:

Firstly, I use a custom Binding to handle localized strings like so:

/// <summary>
/// Handles XAML Bindings to localized strings.
/// </summary>    
public class LocalizedExtension : Binding
{        
    public LocalizedExtension(Defs name)
                : base("[" + name.ToString() + "]")
    {
        this.Mode = BindingMode.OneWay;
        this.Source = TranslationSource.Instance;
    }
}

Defs is an enumeration of all possible translation-keys. For example Defs.pane would be the translation of "Pane" in German, English and so on.

In XAML one would use this binding like so:

<CheckBox
      x:Name="checkA"
      Content="{loc:Localized pane,
                        TargetNullValue='LSG'}" />

Is there a way to have the argument for the binding ("pane") chosen from the enum? So I get the proposals from IntelliSense for the keys instead of having to write the exact string?

Upvotes: 0

Views: 144

Answers (1)

BionicCode
BionicCode

Reputation: 28968

You can use the {x:Static} markup extension:

<CheckBox x:Name="checkA"
          Content="{loc:Localized {x:Static Defs.Pane},
                    TargetNullValue='LSG'}" />

This markup is used to reference constants, static properties, fields and enumeration values. Since it requires strong or explicit types, you will get Intellisense support.

Upvotes: 1

Related Questions