ComponentOne DataGrid for WPF and Silverlight
In This Topic
    Step 3 of 3: Setting the Culture
    In This Topic

    Once you've created resource files for your application, you will need to set the supported cultures for your project and explicitly set the current culture of the project. To do so, complete the following steps:

    1.        In the Solution Explorer, right-click the C1DataGridLocalization project and select Unload Project. Click Yes if Visual Studio asks you to save the project.

    The project will appear grayed out and unavailable.

    2.        Right-click the project again, and select the Edit C1DataGridLocalization.csproj option.

    In the .csproj file, locate the <SupportedCultures></SupportedCultures> tags. Add "es" in between the tags, so they appear similar to the following:

    <SupportedCultures>es</SupportedCultures>

    3.        Save and close the .csproj file.

    4.        In the Solution Explorer, right-click your project and choose Reload Project from the context menu.

    The project will be reloaded and will now support the specified cultures.

    5.        In the Solution Explorer, right-click the MainPage.xaml file and click View Code in the context menu to open the Code Editor.

    6.        Add the following using statements to the top of the file:

    ·         Visual Basic

    Imports System.Globalization

    Imports System.Threading

    ·         C#

    using System.Globalization;

    using System.Threading;

    7.        Add the following code to the MainPage constructor above the InitializeComponent() call to set the CurrentUICulture property:

    ·         Visual Basic

    Thread.CurrentThread.CurrentUICulture = New CultureInfo("es")

    ·         C#

    Thread.CurrentThread.CurrentUICulture = new CultureInfo("es");

    It should now look similar to the following:

    ·         Visual Basic

    Public Sub New()

        ' Set the culture.

        Thread.CurrentThread.CurrentUICulture = New CultureInfo("es")

        InitializeComponent()

        ' Add data to a data source.

        Dim source As New List(Of Data)()

        Dim itemsCount As Integer = 25

        For i As Integer = 0 To itemsCount - 1

            source.Add(New Data())

        Next

        ' Set the grid's ItemsSource property.

        c1dg.ItemsSource = source

    End Sub

    ·         C#

    public MainPage()

    {

        // Set the culture.

        Thread.CurrentThread.CurrentUICulture = new CultureInfo("es");

        InitializeComponent();

        // Add data to a data source.

        List<Data> source = new List<Data>();

        int itemsCount = 25;

        for (int i = 0; i < itemsCount; i++)

        {

            source.Add(new Data()

            {

                ProductName = "Name",

                Description = "Description",

                Quantity = i,

                InStock = (i % 2 == 0)

            });

        }

        // Set the grid's ItemsSource property.

        c1dg.ItemsSource = source;

    }

    8.        Save and run your application.

    9.        To observe some of the localized language strings, select the drop-down filter icon in the grid:

    10.     Click the drop-down arrow in the filter box to view additional strings:

     What You've Accomplished

    In this step you added the file's culture to the project's supported cultures and set that culture to be the current culture. In this tutorial you've learned how to localize an application. You created a resource file, set the project's supported culture, and explicitly set the current culture in code.