Articles in this section
Category / Section

How to localize the header text of dock windows in DockingManager through Resource file?

2 mins read

Localization support is available in UWP DockingManager to localize the text which are used as static in control. Value of Header property in DockingManager can changed dynamically, so we can define localized header directly to the Header property of the DockingManager.

Also, we can retrieve the Header value from the Resource file with the help of external ResourceLoader and DockingResourceWrapper class in the application. The following code demonstrate the same,

 

MainPage.xaml:

  <Page.Resources>
        <local:DockingResourceWrapper x:Key="ResourceWrapperKey"/>
    </Page.Resources>
 
 <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <layout:SfDockingManager Grid.Row="1" x:Name="dockingManager">
            <ContentControl x:Name="contentSchedule" 
                layout:SfDockingManager.Header="{Binding Source={StaticResource ResourceWrapperKey}, Path=MainPageText}"
                layout:SfDockingManager.DockState="Document">
            </ContentControl>
            <ContentControl
                layout:SfDockingManager.Header="{Binding Source={StaticResource ResourceWrapperKey}, Path=StartPageText}"
                layout:SfDockingManager.DockState="Document"/>
        </layout:SfDockingManager>
    </Grid>

 

Also, we can retrieve the localized string and assign the value to the Header in code behind,

           string m_string = new DockingResourceWrapper().MainPageText;
            SfDockingManager.SetHeader(contentSchedule, m_string);
 
            string s_string = new DockingResourceWrapper().StartPageText;
            SfDockingManager.SetHeader(content, s_string);

 

LocalizedResourceLoader.cs

   sealed class LocalizedResourceLoader
    {
        private ResourceLoader resources;        
        private static LocalizedResourceLoader loader = null;
       
        private LocalizedResourceLoader()
        {
            resources = GetLocalizedResourceManager();            
        }
 
        private static ResourceLoader GetLocalizedResourceManager()
        {
            try
            {
                if (Application.Current != null)
                {
                    return ResourceLoader.GetForCurrentView("DockingManager_Localization.Resources");
                }
            }
            catch
            {
 
            }
            return null;
        }
 
 
 
        // Methods
        private static LocalizedResourceLoader GetLoader()
        {
            lock (typeof(LocalizedResourceLoader))
            {
                return LocalizedResourceLoader.loader ?? (LocalizedResourceLoader.loader = new LocalizedResourceLoader());
            }
        }
 
 
        public static string GetString(CultureInfo culture, string name)
        {
            LocalizedResourceLoader sr = LocalizedResourceLoader.GetLoader();
            if (sr == null)
            {
                return null;
            }
 
            string localizedString = sr.resources.GetString(name);
            if (localizedString != string.Empty)
            {
                return localizedString;
            }
 
            return null;
        }
    }

 

DockingResourceWrapper.cs

    public class DockingResourceWrapper
    {
 
        const string mainpage_value = "MainPageText";
 
        /// <summary>
        /// Gets or sets the value of Header of the Dialogbox
        /// </summary>
        public string MainPageText { get; set; }
 
        private string startPage_value = "StartPageText";
 
        public string StartPageText
        {
            get { return startPage_value; }
            set { startPage_value = value; }
        }
 
        public DockingResourceWrapper()
        {
            CultureInfo ci = CultureInfo.CurrentUICulture;
 
            MainPageText = LocalizedResourceLoader.GetString(ci, mainpage_value);
            StartPageText = LocalizedResourceLoader.GetString(ci, startPage_value);
        }
    }

 

Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/DockingManager_Localization_Sample1314986841.zip

 

Conclusion

I hope you enjoyed learning about how to localize the header text of dock windows in DockingManager through Resource file.

You can refer to our UWP DockingManager’s feature tour page to know about its other groundbreaking feature representations. You can also explore our UWP DockingManager documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our UWP DockingManager and other UWP components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied