internal void OnVisualTreeRootSet() { if (VisualTree.XamlElements != null) { return; } if (!string.IsNullOrWhiteSpace(Project.State.OpenFile)) { try { string xml; FileSystem.ReadAllText(Project.State.OpenFile, out xml); if (!string.IsNullOrWhiteSpace(xml)) { var xtr = new XamlTreeReader(xml); xtr.Read(); VisualTree.XamlElements = xtr.All; } } catch (Exception ex) { Log.Error(ex, $"Couldn't load {Project.State.OpenFile}. The XAML output will not be exact."); } } }
public void Should_find_elements() { var xtr = new XamlTreeReader(XAMLTests.TreeReader1); xtr.Read(); Assert.IsTrue(xtr.IsDocumentLoaded); Assert.AreEqual(3, xtr.All.Length); Assert.AreEqual("DesignSurfacePage", xtr.All[0].NodeName); Assert.AreEqual(2, xtr.All[0].Attributes.Count); var entry = xtr.All.First(a => a.NodeName == "Entry"); var fontSize = entry.GetAttributeValue("FontSize"); Assert.AreEqual("18", fontSize); }
public void Should_retain_attached_property_in_original_and_not_in_modified_version() { var xtr = new XamlTreeReader(XAMLTests.AP_Test1_Page); xtr.Read(); var proc = new XamlPostProcessor(); proc.LoadElementDefaults(XAMLTests.AP_Test1_Entry_Defaults); proc.LoadElementDefaults(XAMLTests.AP_Test1_Page_Default); proc.LoadDocument(XAMLTests.AP_Test1_Page_Modified, xtr.All); var doc = proc.Process(); var els = doc.Descendants().ToArray(); var ap1 = els[1].Attributes().FirstOrDefault(a => a.Name.LocalName == "AP.Test1"); var ap2 = els[2].Attributes().FirstOrDefault(a => a.Name.LocalName == "AP.Test1"); Assert.AreEqual("165", ap1.Value); Assert.IsNull(ap2); }