BetterExplorer.Utilities.Load C# (CSharp) Метод

Load() публичный статический Метод

Move somewhere else later
public static Load ( string filename ) : System.Windows.ResourceDictionary
filename string
Результат System.Windows.ResourceDictionary
		public static System.Windows.ResourceDictionary Load(string filename) {
			if (System.IO.File.Exists(filename)) {
				using (var s = new System.IO.FileStream(filename, System.IO.FileMode.Open)) {
					return System.Windows.Markup.XamlReader.Load(s) as System.Windows.ResourceDictionary;
				}
			} else {
				return null;
			}
		}//TODO: Move somewhere else later

Usage Example

Пример #1
0
        /// <summary>
        /// Sets the UI language
        /// </summary>
        /// <param name="culture">Language code (ex. "en-EN")</param>
        /// <param name="filename">The file to load the resources from</param>
        public void SelectCulture(String culture, String filename)
        {
            if (culture == ":null:")
            {
                culture = CultureInfo.InstalledUICulture.Name;
            }

            // List all our resources
            var dictionaryList = new List <ResourceDictionary>(Current.Resources.MergedDictionaries);

            var resourceDictionary = Utilities.Load(filename);

            if (resourceDictionary == null)
            {
                // if not found, then try from the application's resources
                String requestedCulture = $"Locale.{culture}.xaml";
                resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == "/BetterExplorer;component/Translation/" + requestedCulture);
                if (resourceDictionary == null)
                {
                    // If not found, we select our default language
                    requestedCulture   = "DefaultLocale.xaml";
                    resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == "/BetterExplorer;component/Translation/" + requestedCulture);
                }
            }

            // If we have the requested resource, remove it from the list and place at the end.\ 
            // Then this language will be our string table to use.
            if (resourceDictionary != null)
            {
                try {
                    Current.Resources.MergedDictionaries.Remove(resourceDictionary);
                }
                catch {
                }

                Current.Resources.MergedDictionaries.Add(resourceDictionary);
            }

            // Inform the threads of the new culture
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(culture);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
        }