Esempio n. 1
0
        private static void ApplyTheme(FrameworkElement targetElement, Uri dictionaryUri)
        {
            if (targetElement == null) return;

            try
            {
                Theme themeDictionary = null;
                if (dictionaryUri != null)
                {
                    themeDictionary = new Theme();
                    try
                    {
                        themeDictionary.Source = dictionaryUri;
                    }
                    catch (FileNotFoundException e)
                    {

                        ErrorWindow debugWindow = new ErrorWindow("debugging error: Selected Theme Xaml not found \n \n"+e.FusionLog);

                        debugWindow.ShowDialog();
                    }

                    // add the new dictionary to the collection of merged dictionaries of the target object
                    targetElement.Resources.MergedDictionaries.Insert(0, themeDictionary);
                }

                // find if the target element already has a theme applied
                List<Theme> existingDictionaries =
                    (from dictionary in targetElement.Resources.MergedDictionaries.OfType<Theme>()
                     select dictionary).ToList();

                // remove the existing dictionaries
                foreach (Theme thDictionary in existingDictionaries)
                {
                    if (themeDictionary == thDictionary) continue;  // don't remove the newly added dictionary
                    targetElement.Resources.MergedDictionaries.Remove(thDictionary);
                }
            }
            finally { }
        }
Esempio n. 2
0
 /**************************************************************************************************************************
  * Created Alejandro Sosa
 **************************************************************************************************************************/
 private void showErrorMessage(String messageOfDoom)
 {
     ErrorWindow bearerOfBadNews = new ErrorWindow(messageOfDoom);
     bearerOfBadNews.ShowDialog();
 }