Click here to Skip to main content
12,349,778 members (24,362 online)
Click here to Skip to main content

Stats

20.8K views
1.4K downloads
44 bookmarked
Posted

Integrated Help system in a WPF Application

, 20 Jun 2013 CPOL
Quick guideline to understand a workflow of screen without reading long and boring(!!) documentation guide.
IntegratedHelpInWPF
IntegratedHelpInWPF
AttachProperties
bin
Debug
DynamicHelpReference
IntegratedHelpInWPF.vshost.exe.manifest
Commands
DynamicHelpReference
IntegratedHelpInWPF.csproj.user
Languages
Popup
Properties
Resources
IntegratedHelpInWPF.exe
IntegratedHelpInWPF.vshost.exe
IntegratedHelpInWPF.vshost.exe.manifest
Release
IntegratedHelpInWPF.csproj.user
obj
Debug
Resources
TempPE
IntegratedHelpInWPF.vshost.exe.manifest
Converter
IntegratedHelpInWPF.csproj.user
DetailsHelpView.baml
DynamicHelpView.baml
IntegratedHelpInWPF.g.resources
IntegratedHelpInWPF.Properties.Resources.resources
IntegratedHelpInWPF_MarkupCompile.lref
MainWindow.baml
CommonResource.baml
WishlistView.baml
IntegratedHelpInWPF.v11.suo
Assembly
System.Windows.Interactivity.dll
IntegratedHelpInWPF.exe
IntegratedHelpInWPF.pdb
IntegratedHelpInWPF.vshost.exe
IntegratedHelpInWPF.vshost.exe.manifest
System.Windows.Interactivity.dll
IntegratedHelpInWPF.csproj.user
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
DetailsHelpView.baml
DynamicHelpView.baml
IntegratedHelpInWPF.csproj.GenerateResource.Cache
IntegratedHelpInWPF.csprojResolveAssemblyReference.cache
IntegratedHelpInWPF.exe
IntegratedHelpInWPF.g.resources
IntegratedHelpInWPF.pdb
IntegratedHelpInWPF.Properties.Resources.resources
IntegratedHelpInWPF_MarkupCompile.cache
IntegratedHelpInWPF_MarkupCompile.i.cache
IntegratedHelpInWPF_MarkupCompile.lref
MainWindow.baml
CommonResource.baml
Properties.Resources.Designer.cs.dll
WishlistView.baml
IntegratedHelpInWPF.v11.suo
using System;
using System.Collections.Generic;
using System.Resources;
using System.Threading;
using IntegratedHelpInWPF.Properties;

namespace IntegratedHelpInWPF.Languages
{
    public static class LanguageLoader
    {

        //use this dictionary to cache resouce
        private static readonly Dictionary<string, string> CachedText = new Dictionary<string, string>();
        public static void FlushCache()
        {
            CachedText.Clear();
        }
        // used for thread-safety
        private static readonly Object ThreadLock = new Object();
        /// <summary>
        /// Gets the value from the dictionary with the provided key.
        /// </summary>
        /// <param name="key">The key to search from the Dictionary.</param>
        /// <returns>The value of the provided key.</returns>
        public static string GetText(string key)
        {
            try
            {
                lock (ThreadLock)
                {
                    if (CachedText.ContainsKey(key))
                        return CachedText[key];
                    string strLookup = Resources.ResourceManager.GetString(key, Thread.CurrentThread.CurrentUICulture);
                    CachedText.Add(key, strLookup);
                    return strLookup;
                }
            }
            catch (System.ArgumentNullException)
            {
                return String.Format(System.Globalization.CultureInfo.CurrentCulture, "Error 0001 - Unknown Error.");
            }
            catch (System.InvalidOperationException)
            {
                return String.Format(System.Globalization.CultureInfo.CurrentCulture, "Error 0002 - Unknown Error.");
            }
            catch (System.Resources.MissingManifestResourceException)
            {
                return String.Format(System.Globalization.CultureInfo.CurrentCulture, "Error 0003 - Unknown Error.");
            }
        }
        /// <summary>
        /// Gets the value ofr the provided key, and if not found, the default string will
        /// be shown.
        /// </summary>
        /// <param name="key">The key to search from the Dictionary.</param>
        /// <param name="defaultstr">the string that'll be shown if the key is not found.</param>
        /// <returns>The value/default string.</returns>
        public static string GetText(string key, string defaultstr)
        {
            try
            {
                lock (ThreadLock)
                {
                    if (CachedText.ContainsKey(key))
                        return CachedText[key];
                    string result = Resources.ResourceManager.GetString(key, Thread.CurrentThread.CurrentUICulture);

                    if (String.IsNullOrEmpty(result))
                    {
                        return defaultstr;
                    }
                    else
                    {
                        CachedText.Add(key, result);
                        return result;
                    }
                }
            }
            catch (System.ArgumentNullException)
            {
                return defaultstr;
            }
            catch (System.InvalidOperationException)
            {
                return defaultstr;
            }
            catch (System.Resources.MissingManifestResourceException)
            {
                return defaultstr;
            }
        }
        public static ResourceManager ResourceManager
        {
            get { return Resources.ResourceManager; }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Morshed Anwar
Team Leader PracticePRO Software Systems Inc
United States United States
"In my childhood, my uncle has shown me how to see the cloud in a close look and I understand that one can draw some elements of the Earth in the sky-canvas if he/she wants to. After that the cloud becomes closer to me and It teaches me one thing that, a deeper-look to something will give you some clues to draw your imagination. You can able to see that one which you have build-up in your mind.

Years past, I have started my career as a software engineer and has been looking for passion in my coding and development which I should be to enjoy my profession and has started asking myself- 'am I doing any engineering here?!' Is my code becoming that thing which I have designed in my mind? So to find that answer I have tried that old solution here... I have decided to come closer to my code and start analyzing them. And it is really working for me and at least it gives me the confidence that I can build something that I really want to. I can draw my thinking there through my code and can build-up my vision that I have designed in my mind. It also helps me to think out of the box, solve each problems by making blocks and make me careful on each steps." ----- says Morshed Anwar.

• Morshed's Technical Blog site: http://morshedanwar.wordpress.com/

• Morshed's Technical articles those are published in Codeproject site: http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=2992452

• Morshed's Linkedin profile: http://www.linkedin.com/in/morshedanwar

• Morshed's Facebook Profile : http://www.facebook.com/morshed.pulok

Beside all these Morshed like to do - photography and music. Here is Morshed's Flickr photos : http://www.flickr.com/photos/morshed_anwar/

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 20 Jun 2013
Article Copyright 2012 by Morshed Anwar
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid