How to: Make XAML Content Localizable WPF application

Posted by Nantharupan on 10:22 AM in , ,
You may want to localize your XAML content by supplying resource string for XML attributes.
For example you may want to change Content of a button :
 <Button Content="Search">  </Button>

To Make Content Localizable

  1. Create a new resource file.
  2. Make the access modifier of the resource file to public.
  3. create a class that has a public constructor  Define a property that points to the resources. 
  4. public class LocalizedStrings
    {
    public LocalizedStrings()
    {
    }
    private static SilverlightApp.Resource1 resource1 = new SilverlightApp.Resource1();
    public SilverlightApp.Resource1 Resource1 { get { return resource1; } }
    }
    view raw gistfile1.txt hosted with ❤ by GitHub
  5. Open the App.xml file and add the following to the <Application.Resources> section:
  6. <Application.Resources>
    <local:LocalizedStrings xmlns:local ="clr-namespace:appNamespace"
    x:Key="LocalizedStrings" />
    </Application.Resources>
    view raw gistfile1.txt hosted with ❤ by GitHub
  7. To make the Content Localizable; replace the string with 
  8. {Binding Path=resourceFile.resourceName, Source={StaticResource LocalizedStrings }}
    view raw gistfile1.txt hosted with ❤ by GitHub



Popular posts

Copyright © 2009 On the way All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.