예제 #1
0
 public virtual void NotifyResourceDictionaryChanged(ResourceDictionaryChangedEventArgs inEventArgs = null)
 {
     if (null != ResourceDictionaryChangedEvent)
     {
         ResourceDictionaryChangedEvent(this, inEventArgs ?? new ResourceDictionaryChangedEventArgs());
     }
 }
        /// <summary>
        /// Dynamically load a Localization ResourceDictionary from a file
        /// </summary>
        public void SwitchLanguage(string inFiveCharLang, bool inForceSwitch = false)
        {
            if (CultureInfo.CurrentCulture.Name.Equals(inFiveCharLang) && !inForceSwitch)
                return;

            if(!AvailableLanguages.Instance.Contains(inFiveCharLang))
            {
                throw new CultureNotFoundException(String.Format("The language {0} is not available.", inFiveCharLang));
            }

            // Set the new language
            var ci = new CultureInfo(inFiveCharLang);
            Thread.CurrentThread.CurrentCulture = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
            
            string[] xamlFiles = Directory.GetFiles(Path.Combine(DefaultPath, inFiveCharLang), "*.xaml");

            // If there are no files, do nothing
            if (xamlFiles.Length == 0)
                return;

            FileNames = new List<string>(xamlFiles);

            // Remove previous ResourceDictionaries
            RemoveGlobalizationResourceDictionaries();

            // Add new Resource Dictionaries
            LoadDictionariesFromFiles(FileNames);
            var args = new ResourceDictionaryChangedEventArgs { ResourceDictionaryPaths = FileNames };
            NotifyResourceDictionaryChanged(args);
        }
예제 #3
0
        /// <summary>
        /// Dynamically load a Localization ResourceDictionary from a file
        /// </summary>
        public void SwitchLanguage(string inFiveCharLang, bool inForceSwitch = false)
        {
            if (CultureInfo.CurrentCulture.Name.Equals(inFiveCharLang) && !inForceSwitch)
            {
                return;
            }

            if (!AvailableLanguages.Instance.Contains(inFiveCharLang))
            {
                throw new CultureNotFoundException(string.Format("The language {0} is not available.", inFiveCharLang));
            }

            // Set the new language
            var ci = new CultureInfo(inFiveCharLang);

            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;

            FileNames = new List <string>();
            string[] xamlFiles;

            // check if the switch to language matches the fallback language
            if (!inFiveCharLang.Equals(FallBackLanguage))
            {
                // switch to language is different, must load the fallback language first
                xamlFiles = Directory.GetFiles(Path.Combine(DefaultPath, FallBackLanguage), $"{FallBackLanguage}.xaml");
                if (xamlFiles.Length > 0)
                {
                    FileNames.AddRange(xamlFiles);
                }
            }

            // load the switch to language
            xamlFiles = Directory.GetFiles(Path.Combine(DefaultPath, inFiveCharLang), $"{inFiveCharLang}.xaml");
            if (xamlFiles.Length > 0)
            {
                FileNames.AddRange(xamlFiles);
            }

            // Remove previous ResourceDictionaries
            RemoveResourceDictionaries();

            // Add new Resource Dictionaries
            LoadDictionariesFromFiles(FileNames);
            var args = new ResourceDictionaryChangedEventArgs {
                ResourceDictionaryPaths = FileNames, ResourceDictionaryNames = FileNames.Select(f => Path.GetFileNameWithoutExtension(f)).ToList()
            };

            NotifyResourceDictionaryChanged(args);
        }
예제 #4
0
        /// <summary>
        /// Dynamically load a Localization ResourceDictionary from a file
        /// </summary>
        public void SwitchStyle(string inStyleName, bool inForceSwitch = false)
        {
            if (AvailableStyles.Instance.SelectedStyle.Equals(inStyleName) && !inForceSwitch)
            {
                return;
            }

            if (!AvailableStyles.Instance.Contains(inStyleName))
            {
                throw new StyleNotFoundException(String.Format("The style {0} is not available.", inStyleName));
            }

            // Set the new style
            AvailableStyles.Instance.SelectedStyle = inStyleName;

            FileNames = new List <string>();
            string[] xamlFiles;

            // check if the switch to style matches the fallback style
            if (!inStyleName.Equals(FallBackStyle))
            {
                // switch to style is different, must load the fallback style first
                xamlFiles = Directory.GetFiles(DefaultPath, $"{FallBackStyle}.xaml");
                if (xamlFiles.Length > 0)
                {
                    FileNames.AddRange(xamlFiles);
                }
            }

            // load the switch to style
            xamlFiles = Directory.GetFiles(DefaultPath, $"{inStyleName}.xaml");
            if (xamlFiles.Length > 0)
            {
                FileNames.AddRange(xamlFiles);
            }

            // Remove previous ResourceDictionaries
            RemoveResourceDictionaries();

            // Add new Resource Dictionaries
            LoadDictionariesFromFiles(FileNames);
            var args = new ResourceDictionaryChangedEventArgs {
                ResourceDictionaryPaths = FileNames, ResourceDictionaryNames = FileNames.Select(f => Path.GetFileNameWithoutExtension(f)).ToList()
            };

            NotifyResourceDictionaryChanged(args);
        }
예제 #5
0
        /// <summary>
        /// Dynamically load a Localization ResourceDictionary from a file
        /// </summary>
        public void SwitchStyle(String inFileName, string inResourceDictionaryName = null)
        {
            string path = inFileName;
            if (!File.Exists(path) && !path.Contains(@":\"))
                path = Path.Combine(GlobalizedApplication.Instance.Directory, SubDirectory, inFileName);
            if (File.Exists(path))
            {
                RemoveResourceDictionaries();
                MergedDictionaries.Add(LoadFromFile(path) as StyleResourceDictionary);
                var args = new ResourceDictionaryChangedEventArgs();
                args.ResourceDictionaryNames.Add(Path.GetFileNameWithoutExtension(inFileName));
                args.ResourceDictionaryPaths.Add(path);

                NotifyResourceDictionaryChanged(args);
            }
            else
            {
                Debug.WriteLine("ResourceDictionary not found: " + inFileName);
            }
        }
예제 #6
0
        /// <summary>
        /// Dynamically load a Localization ResourceDictionary from a file
        /// </summary>
        public void SwitchLanguage(string inFiveCharLang, bool inForceSwitch = false)
        {
            if (CultureInfo.CurrentCulture.Name.Equals(inFiveCharLang) && !inForceSwitch)
            {
                return;
            }

            if (!AvailableLanguages.Instance.Contains(inFiveCharLang))
            {
                throw new CultureNotFoundException(string.Format("The language {0} is not available.", inFiveCharLang));
            }

            // Set the new language
            var ci = new CultureInfo(inFiveCharLang);

            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;

            string[] xamlFiles = Directory.GetFiles(Path.Combine(DefaultPath, inFiveCharLang), "*.xaml");

            // If there are no files, do nothing
            if (xamlFiles.Length == 0)
            {
                return;
            }

            FileNames = new List <string>(xamlFiles);

            // Remove previous ResourceDictionaries
            RemoveGlobalizationResourceDictionaries();

            // Add new Resource Dictionaries
            LoadDictionariesFromFiles(FileNames);
            var args = new ResourceDictionaryChangedEventArgs {
                ResourceDictionaryPaths = FileNames
            };

            NotifyResourceDictionaryChanged(args);
        }
예제 #7
0
        /// <summary>
        /// Dynamically load a Localization ResourceDictionary from a file
        /// </summary>
        public void SwitchStyle(string inFileName, string inResourceDictionaryName = null)
        {
            string path = inFileName;

            if (!File.Exists(path) && !path.Contains(@":\"))
            {
                path = Path.Combine(GlobalizedApplication.Instance.Directory, SubDirectory, inFileName);
            }
            if (File.Exists(path))
            {
                RemoveResourceDictionaries();
                MergedDictionaries.Add(LoadFromFile(path) as StyleResourceDictionary);
                var args = new ResourceDictionaryChangedEventArgs();
                args.ResourceDictionaryNames.Add(Path.GetFileNameWithoutExtension(inFileName));
                args.ResourceDictionaryPaths.Add(path);

                NotifyResourceDictionaryChanged(args);
            }
            else
            {
                Debug.WriteLine("ResourceDictionary not found: " + inFileName);
            }
        }
예제 #8
0
        private void GlobalizationManager_ResourceDictionaryChangedEvent(object sender, ResourceDictionaryChangedEventArgs args)
        {
            if (args == null || args.ResourceDictionaryNames == null || args.ResourceDictionaryNames[0] == null)
            {
                return;
            }

            SelectedStyle = args.ResourceDictionaryNames[0];
        }
예제 #9
0
 private void GlobalizationManager_ResourceDictionaryChangedEvent(object sender, ResourceDictionaryChangedEventArgs e)
 {
     NotifyPropertyChanged("SelectedStyle");
 }
 public virtual void NotifyResourceDictionaryChanged(ResourceDictionaryChangedEventArgs inEventArgs = null)
 {
     ResourceDictionaryChangedEvent?.Invoke(this, inEventArgs ?? new ResourceDictionaryChangedEventArgs());
 }