Beispiel #1
0
        private void WriteUnprocessedNode(string indent, UnprocessedNode unprocessedNode)
        {
            char[] text = unprocessedNode.Text.ToCharArray();
            XamlFormatter.UnprocessedNodeFormatting nodeFormatting = this.GetNodeFormatting(unprocessedNode);
            if (nodeFormatting.LeadingWhitespace != null)
            {
                this.writer.SetWhitespace(nodeFormatting.LeadingWhitespace);
                if (unprocessedNode.IndentingBehavior == IndentingBehavior.FromContainer && this.writer.LineBreakCount > 0)
                {
                    this.writer.SetIndent(indent);
                }
            }
            int length = this.writer.Length;

            this.writer.WriteRawText(text, text.Length);
            if (this.shouldUpdateSourceContext && unprocessedNode.SourceContextReference != null)
            {
                unprocessedNode.SourceContextReference.OffsetSourceContext(length);
            }
            if (nodeFormatting.TrailingWhitespace == null)
            {
                return;
            }
            this.writer.SetWhitespace(nodeFormatting.TrailingWhitespace);
        }
Beispiel #2
0
        private XamlFormatter.UnprocessedNodeFormatting GetNodeFormatting(UnprocessedNode unprocessedNode)
        {
            XamlFormatter.UnprocessedNodeFormatting unprocessedNodeFormatting = new XamlFormatter.UnprocessedNodeFormatting();
            XamlSourceContext sourceContext = unprocessedNode.SourceContextReference.SourceContext;

            if (sourceContext != null && sourceContext.TextRange != null)
            {
                unprocessedNodeFormatting.LeadingWhitespace  = XamlFormatter.GetLeadingWhitespace(sourceContext);
                unprocessedNodeFormatting.TrailingWhitespace = XamlFormatter.GetTrailingWhitespace(sourceContext);
            }
            return(unprocessedNodeFormatting);
        }