Hi.
I using RadDocking for several languages with Resouce dictionary(DynamicResource in xaml).
if I Switching languages at runtime without LoadLayout() function then it works.
But If i use LoadLayout() at startup then switching language not working.
(Switching Style at runtime is still works with LoadLayout() )
Can anybody help this problem?
3 Answers, 1 is accepted
Could you please provide more details on the exact approach you've taken for switching the languages at runtime?
It would really be of help if you could open a new support ticket and send over a small sample project that demonstrates the issue so that I can investigate and further assist you.
Thank you in advance for your cooperation on the matter.
Regards,
Dilyan Traykov
Progress Telerik
Hello.
Here small sample project.
Please check part of MainWindow() creator.
MainWindow.xaml
--------------------------------------------------
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFResourceTest"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="WPFResourceTest.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="800" Width="700" Closed="Window_Closed">
<Grid>
<DockPanel>
<telerik:RadMenu DockPanel.Dock="Top">
<telerik:RadMenuItem Header="{DynamicResource keyLanguage}">
<telerik:RadMenuItem Header="{DynamicResource keyEnglish}" Tag="en-US" Click="MenuItem_Language_Click" />
<telerik:RadMenuItem Header="{DynamicResource keyKorean}" Tag="ko-KR" Click="MenuItem_Language_Click" />
</telerik:RadMenuItem>
</telerik:RadMenu>
<telerik:RadDocking HasDocumentHost="True" x:Name="mainDocking">
<telerik:RadSplitContainer InitialPosition="DockedLeft">
<telerik:RadPaneGroup >
<telerik:RadPane Header="{DynamicResource keyProjects}" telerik:RadDocking.SerializationTag="keyProjects">
</telerik:RadPane>
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>
<telerik:RadSplitContainer>
<telerik:RadPaneGroup >
<telerik:RadPane Header="{DynamicResource keyContent1}"/>
<telerik:RadPane Header="{DynamicResource keyContent2}"/>
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>
<telerik:RadSplitContainer InitialPosition="DockedRight" >
<telerik:RadPaneGroup >
<telerik:RadPane Header="{DynamicResource keyProperty}" telerik:RadDocking.SerializationTag="keyProperty">
</telerik:RadPane>
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>
</telerik:RadDocking>
</DockPanel>
</Grid>
</Window>
--------------------------------------------------
MainWindow.xaml.cs
--------------------------------------------------
using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows;
using Telerik.Windows.Controls;
namespace WPFResourceTest
{
/// <summary>
/// MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
//If I Call this line, language changing not works.
//If annotation this line, language changing works.
LoadDockingLayoutFromFile();
}
private void Window_Closed(object sender, EventArgs e)
{
SaveDockingLayoutToFile();
}
private void MenuItem_Language_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
SwitchingLanguage(((RadMenuItem)sender).Tag.ToString());
}
protected void SwitchingLanguage(string sLanguage)
{
ResourceDictionary _Windows = Application.Current.Resources.MergedDictionaries[1];
ResourceDictionary _Windows_Controls = Application.Current.Resources.MergedDictionaries[2];
ResourceDictionary _Windows_Controls_Navigation = Application.Current.Resources.MergedDictionaries[3];
ResourceDictionary _Windows_Controls_Docking = Application.Current.Resources.MergedDictionaries[4];
Application.Current.Resources.MergedDictionaries.Clear(); //Clear
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(sLanguage);
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
{
Source = new Uri(@"/Resources/Resource." + sLanguage + ".xaml", UriKind.Relative)
});
Application.Current.Resources.MergedDictionaries.Add(_Windows);
Application.Current.Resources.MergedDictionaries.Add(_Windows_Controls);
Application.Current.Resources.MergedDictionaries.Add(_Windows_Controls_Navigation);
Application.Current.Resources.MergedDictionaries.Add(_Windows_Controls_Docking);
}
private void SaveDockingLayoutToFile()
{
using (IsolatedStorageFile storate = IsolatedStorageFile.GetUserStoreForAssembly())
{
using (var isoStream = storate.OpenFile("RadDocking_Layout.xml", FileMode.Create))
{
this.mainDocking.SaveLayout(isoStream);
isoStream.Seek(0, SeekOrigin.Begin);
StreamReader reader2 = new StreamReader(isoStream);
}
}
}
private void LoadDockingLayoutFromFile()
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForAssembly())
{
if (storage.FileExists("RadDocking_Layout.xml"))
{
using (var isoStream = storage.OpenFile("RadDocking_Layout.xml", FileMode.Open))
{
this.mainDocking.LoadLayout(isoStream);
}
}
}
}
}
}
--------------------------------------------------
App.xaml
--------------------------------------------------
<Application x:Class="WPFResourceTest.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFResourceTest"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/Resource.en-US.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Green;component/Themes/System.Windows.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Green;component/Themes/Telerik.Windows.Controls.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Green;component/Themes/Telerik.Windows.Controls.Navigation.xaml" />
<ResourceDictionary Source="/Telerik.Windows.Themes.Green;component/Themes/Telerik.Windows.Controls.Docking.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
--------------------------------------------------
Resource.en-US.xaml
--------------------------------------------------
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFResourceTest.Resources"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="keyLanguage">Language</system:String>
<system:String x:Key="keyKorean">Korean</system:String>
<system:String x:Key="keyEnglish">English</system:String>
<system:String x:Key="keyProjects">Projects</system:String>
<system:String x:Key="keyContent1">Content 1</system:String>
<system:String x:Key="keyContent2">Content 2</system:String>
<system:String x:Key="keyProperty">Property</system:String>
</ResourceDictionary>
--------------------------------------------------
Resource.ko-KR.xaml
--------------------------------------------------
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFResourceTest.Resources"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="keyLanguage">언어(Language)</system:String>
<system:String x:Key="keyKorean">한국어(Korean)</system:String>
<system:String x:Key="keyEnglish">영어(English)</system:String>
<system:String x:Key="keyProjects">프로젝트(Projects)</system:String>
<system:String x:Key="keyContent1">내용 1(Content 1)</system:String>
<system:String x:Key="keyContent2">내용 2(Content 2)</system:String>
<system:String x:Key="keyProperty">속성(Property)</system:String>
</ResourceDictionary>
--------------------------------------------------
thank you.
A similar scenario has been discussed in this forum thread. As suggested by my colleagues there, the RadDocking control saves only the Header text and the dynamic resource reference is lost in the process.
To modify this behavior, you should handle the ElementLoaded event of the control and update the header content there similarly to the approach my colleague has demonstrated in this reply.
I hope you find this helpful. If you need any further assistance, please let me know.
Regards,
Dilyan Traykov
Progress Telerik