- antsonthetree
- Posts: 44
- Joined:
Unity Modify ResourceDictionary at Runtime
Hello,
I have the code below that works fine in Blend - the strings are all updated when the button is clicked, but does not work with Noesis/Unity. Is this currently supported? The idea is to change the language strings at runtime.
I have the code below that works fine in Blend - the strings are all updated when the button is clicked, but does not work with Noesis/Unity. Is this currently supported? The idea is to change the language strings at runtime.
Code: Select all
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Name="ThemeDictionary">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Strings-EN.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<ResourceDictionary Source="Styles/Res_MainMenu.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
public ResourceDictionary ThemeDictionary
{
// You could probably get it via its name with some query logic as well.
get { return (ResourceDictionary) Resources.MergedDictionaries[0]; }
}
public void ChangeTheme()
{
#if NOESIS
Debug.Log(((ResourceDictionary)ThemeDictionary.MergedDictionaries[0]).Source);
string uri = "Assets/NoesisGUI/Styles/Strings-ES.xaml";
//ThemeDictionary.MergedDictionaries.Clear();
//ThemeDictionary.MergedDictionaries.Add(new ResourceDictionary() { Source = uri });
((ResourceDictionary)ThemeDictionary.MergedDictionaries[0]).Source = uri;
Debug.Log(((ResourceDictionary)ThemeDictionary.MergedDictionaries[0]).Source);
#else
Console.WriteLine(ThemeDictionary.MergedDictionaries[0].Source.ToString());
System.Uri uri = new System.Uri("Assets/NoesisGUI/Styles/Strings-ES.xaml", System.UriKind.Relative);
ThemeDictionary.MergedDictionaries.Clear();
ThemeDictionary.MergedDictionaries.Add(new ResourceDictionary() { Source = uri });
//Uri uri = new Uri("Styles/Strings-ES.xaml", UriKind.Relative);
//ThemeDictionary.MergedDictionaries[0].Source = uri;
Console.WriteLine(ThemeDictionary.MergedDictionaries[0].Source.ToString());
#endif
}
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Unity Modify ResourceDictionary at Runtime
Hi,
It seems to be a bug in the MergedDictionaries change notifications.
Could you please create a ticket in our bugtracker attaching that sample?
Thanks.
It seems to be a bug in the MergedDictionaries change notifications.
Could you please create a ticket in our bugtracker attaching that sample?
Thanks.