Category / Section
How to dynamically switch between more than one languages through localization?
1 min read
Steps to switch between more than one language dynamically through localization
Make sure to include all necessary resource keywords for the required assemblies (e.g.,
Syncfusion.Shared.WPF
) in the localized resource files. Additionally, provide resource files for all the required languages.-
When switching from one language to another, the controls must be refreshed to reflect the new localization. To refresh the controls, apply the updated resources by creating a
ResourceDictionary
dynamically in code.
In the example below, we override the Office2016Colorful
style of the ColorPickerPalette
control and apply the resources dynamically within the button click event.
Example
C#
ResourceDictionary rd = new ResourceDictionary(); private void French_Click(object sender, RoutedEventArgs e) { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR"); System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR"); ApplyResourceDictionary(); } public void ApplyResourceDictionary() { colorPickerPalette.UpdateLayout(); // To refresh the control dynamically rd.Source = new Uri("pack://application:,,,/Office2016Colorful_Overriden.xaml", UriKind.RelativeOrAbsolute); this.Resources.MergedDictionaries.Add(rd); }
VB
Private rd As New ResourceDictionary() Private Sub French_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("fr-FR") System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("fr-FR") ApplyResourceDictionary() End Sub Public Sub ApplyResourceDictionary() colorPickerPalette.UpdateLayout() ' To refresh the control dynamically rd.Source = New Uri("pack://application:,,,/Office2016Colorful_Overriden.xaml", UriKind.RelativeOrAbsolute) Me.Resources.MergedDictionaries.Add(rd) End Sub
Sample: www.syncfusion.com/downloads/support/directtrac/213571/ze/COLORP~1-303420562