Пример #1
0
        private void WriteElementToXml(XmlWriter writer, FrameworkElement item)
        {
            if (item == null)
            {
                return;
            }

            writer.WriteStartElement(item.GetType().ToString());
            var coordinates = item.GetCoordinatesInView(this.Automator.VisualRoot);
            var rect        = item.GetRect(this.Automator.VisualRoot);
            var attributes  = new Dictionary <string, string>
            {
                { "name", item.AutomationName() },
                { "id", item.AutomationId() },
                { "xname", item.Name },
                {
                    "visible",
                    item.IsUserVisible(this.Automator.VisualRoot)
                    .ToString()
                    .ToLowerInvariant()
                },
                { "value", item.GetText() },
                { "x", rect.X.ToString(CultureInfo.InvariantCulture) },
                { "y", rect.Y.ToString(CultureInfo.InvariantCulture) },
                {
                    "width",
                    rect.Width.ToString(CultureInfo.InvariantCulture)
                },
                {
                    "height",
                    rect.Height.ToString(CultureInfo.InvariantCulture)
                },
                {
                    "clickable_point",
                    coordinates.ToString(CultureInfo.InvariantCulture)
                }
            };

            foreach (var attribute in attributes)
            {
                writer.WriteAttributeString(attribute.Key, attribute.Value);
            }

            var children = Finder.GetChildren(item);

            if (item == this.Automator.VisualRoot)
            {
                children = children.Concat(Finder.GetPopupsChildren());
            }

            foreach (var child in children)
            {
                this.WriteElementToXml(writer, child as FrameworkElement);
            }

            writer.WriteEndElement();
        }