c# - Change Language programmatically Like english to french wpf -


i found tutorials , added 2 resources file properties folder of project , named them "resources.tr-tr.resx" , "resources.en-us.resx" , default "resources.resx" file there. set access modifier "public". , call in xaml code

content="{x:static p:resources.mainwindow}"

in files has values , can see reads correct. have menu button changes language , in action method write

private void englishlanguagemenubutton_click(object sender, routedeventargs e) {       system.threading.thread.currentthread.currentuiculture = new   system.globalization.cultureinfo("en-us"); } 

or in action lets say

private void macedonianlanguagemenubutton_click(object sender, routedeventargs e) {     system.threading.thread.currentthread.currentuiculture = new system.globalization.cultureinfo("tr-tr"); } 

however system doesnt work. missing ? can dynamically change language ? or how can change resx file dynamically

thanks

try this

add code in application

/// <summary>     /// wraps xaml access instance of wpflocalize.properties.resources, list of available cultures, , method change culture     /// </summary>     public class cultureresources     {         /// <summary>         /// backing filed provider         /// </summary>         private static objectdataprovider provider;          /// <summary>         /// gets resource provider         /// </summary>         public static objectdataprovider resourceprovider         {                         {                 if (provider == null)                 {                     provider = (objectdataprovider)app.current.findresource("resources");                 }                  return provider;             }         }          /// <summary>         /// change current culture used in application.         /// if desired culture available localized elements updated.         /// </summary>         /// <param name="culture">culture change to</param>         public static void changeculture(cultureinfo culture)         {             ////remain on current culture if desired culture cannot found             //// - otherwise revert default resources set, may or may not desired.              v_parcel.properties.resources.culture = culture;             resourceprovider.refresh();         }          /// <summary>         /// resources objectdataprovider uses method instance of wpflocalize.properties.resources class         /// </summary>         /// <returns>returns resource instance</returns>         public v_parcel.properties.resources getresourceinstance()         {             return new v_parcel.properties.resources();         }     } 

add xaml culturedictionary

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                     xmlns:resource="clr-namespace:cultures">      <!-- resources odp contains current instance of wpflocalize.properties.resources class.        used in bindings localized strings , automatic updates when culture updated -->     <objectdataprovider x:key="resources" objecttype="{x:type resource:cultureresources}" methodname="getresourceinstance" />  </resourcedictionary> 

in app.xaml

 <resourcedictionary.mergeddictionaries>                 <resourcedictionary source="culturedictionary.xaml"/> 

binding should like

content="{binding showterminalname,source={staticresource resources}}" 

and in culture change event write this

thread.currentthread.currentculture = new cultureinfo(currentculture);                     thread.currentthread.currentuiculture = new cultureinfo(currentculture);                      cultureinfo cultureinfo = new cultureinfo(currentculture);                     cultureresources.changeculture(cultureinfo); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -