/// <summary> /// Holds routines that are useful in multiple actions. /// </summary> public static string Generate() { SetupXamlInformation compileFeatures = new SetupXamlInformation(); _EnsureInitialized(); return(_GenerateTree(_generator, compileFeatures)); }
/// <summary> /// /// </summary> public static string PostProcess(string xmlContent, SetupXamlInformation ppParams) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlContent); CleanupXamlFile(xmlDoc, ppParams); ApplyResourceKeysInXaml(xmlDoc); return(xmlDoc.OuterXml); }
private static void CleaningResources(XmlNode node, SetupXamlInformation ppParams) { if (WPFXamlGenerator.IsResourceDictionaryNode(node)) { foreach (XmlNode childResourceNode in node.ChildNodes) { XmlElement childResource = childResourceNode as XmlElement; if (childResource == null) { continue; } if (!GetXSharedXmlNodeValue(childResource)) { // x:Shared is value is already False; continue; } Type resourceType = FindType(childResource); if (typeof(Visual).IsAssignableFrom(resourceType) || typeof(ContentElement).IsAssignableFrom(resourceType)) { if (!ppParams.EnableXamlCompilationFeatures) { node.RemoveChild(childResourceNode); } else { WPFXamlGenerator.SetXSharedValue(childResource, "false"); } } } } else { foreach (XmlNode n in node.ChildNodes) { CleaningResources(n, ppParams); } } }
private static string _GenerateTree(XamlGenerator generator, SetupXamlInformation setupXamlInfo) { if (setupXamlInfo == null) { throw new ArgumentNullException("setupXamlInfo"); } _setupXamlInfo = setupXamlInfo; // // Generate xaml using XamlGenerator. // Note: generator code was referenced from ClientTestLibrary directory. // int maxTotalElements = _xamlDefinition.MaxTotalElements; int maxAttributes = _xamlDefinition.MaxAttributes; int maxChildren = _xamlDefinition.MaxChildren; int maxDepth = _xamlDefinition.MaxDepth; DateTime start = DateTime.Now; Stream stream = generator.CreateStream(maxDepth, maxAttributes, maxChildren); // maxDepth, maxAttributes, maxChildren string xaml = ""; // Store xaml in string. using (StreamReader sr = new StreamReader(stream)) { xaml = sr.ReadToEnd(); } xaml = ModifyXaml.PostProcess(xaml, setupXamlInfo); OnXamlGenerated(xaml); // // Return root of generated tree or the string depending of the parseXaml argument. // return(xaml); }
/// <summary> /// /// </summary> private static void CleanupXamlFile(XmlDocument xmlDoc, SetupXamlInformation ppParams) { CleaningResources(xmlDoc.DocumentElement, ppParams); }
/// <summary> /// Holds routines that are useful in multiple actions. /// </summary> public static string GenerateWindow(SetupXamlInformation compileFeatures) { _EnsureInitialized(); return(_GenerateTree(_windowGenerator, compileFeatures)); }
/// <summary> /// Holds routines that are useful in multiple actions. /// </summary> public static string GenerateResourceDictionary(SetupXamlInformation compileFeatures) { _EnsureInitialized(); return(_GenerateTree(_resourceGenerator, compileFeatures)); }
/// <summary> /// Holds routines that are useful in multiple actions. /// </summary> public static string GenerateFreezable(SetupXamlInformation compileFeatures) { _EnsureInitialized(); return(_GenerateTree(_freezableGenerator, compileFeatures)); }