Ricardo Dorta

Hi all,

Is it possible to bind the content property of a label to a dynamic resource that contains a string

That’s because i’m doing a double culture software (pt-br & en-us).

And i’m trying to do use the resources to change all the words in a screen like I already do with the apps skins.

I could do it using StaticResource, but this way i have to close all windows thar were already open in the application.

I hope anyone can help.

Thanks anyway.

Ricardo Dorta




Re: Windows Presentation Foundation (WPF) Text as DynamicResource

Dr. WPF

Here is a very simple sample of swapping resource dictionaries to provide dynamic culture switching.

Here's the crux of the code:

Code Snippet

public partial class App : Application

{

ResourceDictionary _currentCultureDictionary = null;

void AppStartup(object sender, StartupEventArgs e)

{

LoadCultureStrings("en-US");

}

internal void LoadCultureStrings(string name)

{

ResourceDictionary newCultureDictionary = null;

try

{

newCultureDictionary = App.LoadComponent(

new Uri("/resources/" + name + ".xaml",

UriKind.Relative)) as ResourceDictionary;

}

catch (Exception ex) {}

if (newCultureDictionary != null)

{

if (_currentCultureDictionary != null)

{

Application.Current.Resources.MergedDictionaries

.Remove(_currentCultureDictionary);

}

_currentCultureDictionary = newCultureDictionary;

Thread.CurrentThread.CurrentUICulture = new CultureInfo(name);

this.Resources.MergedDictionaries.Add(newCultureDictionary);

}

}

}