コード例 #1
0
        public Merger(SystemTarget target, bool isTestMode)
        {
            _target = target;

            _rootFolderPath = !isTestMode
                                                  ? FilePaths.GenerateXamlSearchFolderPath()
                                                  : FilePaths.GetExecutingAssemblyFilePath();
        }
コード例 #2
0
        public string GenerateGenericXamlFile()
        {
            var        nameSpace        = GetValidNameSpaceDeclareStyle();
            var        nameSpaces       = new List <XAttribute>();
            XNamespace defaultNameSpace = "";

            foreach (var ns in _nameSpaces)
            {
                var key = ns.Key;

                if (key.StartsWith(Constants.Xmlns))
                {
                    key = key.TrimStart(Constants.Xmlns).TrimStart(Constants.Colon);
                }

                var value = ns.Value.StartsWith(Constants.Http, StringComparison.InvariantCultureIgnoreCase)
                                                    ? ns.Value
                                                    : string.Format("{0}{1}{2}", nameSpace, Constants.Colon, ns.Value);

                if (string.IsNullOrEmpty(key))
                {
                    defaultNameSpace = value;
                    nameSpaces.Add(new XAttribute(Constants.Xmlns, value));
                }
                else
                {
                    nameSpaces.Add(new XAttribute(XNamespace.Xmlns + key, value));
                }
            }

            var root = new XElement(defaultNameSpace + Constants.ResourceDictionaryNode);

            root.Add(new XComment(_target.ToString()));

            foreach (var ns in nameSpaces)
            {
                root.Add(ns);
            }

            if (_target == SystemTarget.WindowsStore)
            {
                var rootThemeNode = new XElement(defaultNameSpace + Constants.ThemeDictionariesNode);
                root.Add(rootThemeNode);

                CreateThemedResourceNode(_resourcesWinStoreDefault, Constants.DefaultTheme, rootThemeNode, defaultNameSpace);
                CreateThemedResourceNode(_resourcesWinStoreLight, Constants.LightTheme, rootThemeNode, defaultNameSpace);
                CreateThemedResourceNode(_resourcesWinStoreHighContrast, Constants.HighContrastTheme, rootThemeNode, defaultNameSpace);
            }

            foreach (var resource in _resources)
            {
                root.Add(resource.Value);
            }

            foreach (var style in _styles)
            {
                root.Add(style.Value);
            }

            root.Save(FilePaths.GenerateGenericFilePath(_target));

            return(root.ToString());
        }