static Dictionary<string, DependencyProperty> GetThemePropertyTable(Theme theme)
        {
            Dictionary<string, DependencyProperty> table;

            if (!themePropertiesTable.TryGetValue(theme.GetType(), out table))
            {
                table = theme.GetType().GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
                    .Select(fi => fi.GetValue(null) as DependencyProperty)
                    .ToDictionary(dp => dp.Name);
                themePropertiesTable.Add(theme.GetType(), table);
            }

            return table;
        }
        public static XElement SaveTheme(Theme theme)
        {
            var themeProps = theme.GetType().GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy)
                .Where(fi => fi.FieldType == typeof(DependencyProperty))
                .Select(fi => (DependencyProperty)fi.GetValue(null))
                .Where(dp => !dp.ReadOnly);

            var element = new XElement("Theme",
                new XAttribute("Name", theme.ThemeName),
                new XAttribute("Type", theme.GetType().AssemblyQualifiedName),
                themeProps.Select(dp => CreatePropertyElement(theme, dp)));

            if (theme.Palette.Count > 0)
            {
                element.Add(new XElement("Palette", theme.Palette.Select(pc => new XElement("PaletteColor", new XAttribute("Name", pc.Name), new XAttribute("Color", pc.Color)))));
            }

            return element;
        }