Is there any way to create a dynamic list of strings (based on language) in XAML (Silverlight)?

Just wondering if it is possible to dynamically create a list of strings in XAML based on language/culture? Say if user logs in as an English user it shows Client Name, Order Number... and if user logs in as a Polish user it shows Nazwa klienta, Numer zamówienia instead?

I only know the hardcoded one like below:

        <System_Collections_Generic:List`1 x:Key="columnNameList">
            <System:String>Client Name</System:String>
            <System:String>Order Number</System:String>
            <System:String>Date</System:String>
        </System_Collections_Generic:List`1>

Answers


I would suggest using a resource file and a markup extension. In the resource file, you create string ressources, and you make localized resource files for each language. In the markup extension, you just return the value of the string from the resources (it will automatically pick up the appropriate language from the satellite resource assembly for the current culture).

Markup extension

[MarkupExtensionReturnType(typeof(string))]
public class ResourceString : MarkupExtension
{
    [ConstructorArgument("resourceKey")]
    public string ResourceKey { get; set; }

    public ResourceString(string resourceKey)
    {
        this.ResourceKey = resourceKey;
    }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        // Assuming your resource file is named StringResources.resx
        return StringResources.ResourceManager.GetString(ResourceKey);
    }
}

XAML

    <local:ListOfStrings x:Key="columnNameList">
        <local:ResourceString ResourceKey="ClientName" />
        <local:ResourceString ResourceKey="OrderNumber" />
        <local:ResourceString ResourceKey="Date" />
    </local:ListOfStrings>

By the way, you can't use generics in XAML (well, you can in XAML 2009, but it's not supported in VS yet). So you need to create a non generic class that represents a list of strings :

public class ListOfStrings : List<string> { }

Need Your Help

How can I make an HTML pop-up menu with Perl?

perl

I need to create HTML pop-up menu using Perl. Can anyone help me?

SVM - Can I normalize W vector?

machine-learning computer-vision svm

In SVM, there is something wrong with normalize W vector such: