Пример #1
0
        public static string ExportThemeAsXaml(ThemeProfile profile)
        {
            const string resourceDictionaryStart =
                "<ResourceDictionary xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " +
                "xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">";

            const string resourceDictionaryEnd = "</ResourceDictionary>";

            var rd = profile.CreateResourceDictionary();
            // create resource dictionary
            var content = rd.Keys.OfType <string>()
                          .OrderBy(s => s)
                          .Select(s =>
            {
                var res   = rd[s];
                var brush = res as SolidColorBrush;
                if (brush != null)
                {
                    return("<SolidColorBrush x:Key=\"" + s + "\">" +
                           brush.Color.ToColorString() +
                           "</SolidColorBrush>");
                }
                if (res is Color)
                {
                    return("<Color x:Key=\"" + s + "\">" +
                           ((Color)res).ToColorString() +
                           "</Color>");
                }
                return(String.Empty);
            })
                          .Where(s => !String.IsNullOrEmpty(s))
                          .JoinString(Environment.NewLine);

            return(resourceDictionaryStart + Environment.NewLine +
                   content + Environment.NewLine +
                   resourceDictionaryEnd);
        }