Ejemplo n.º 1
0
        public void RemoveEmptyLines()
        {
            // Set start an undo command if we can
            TextBoxBase textBox = _doc.Parent as TextBoxBase;

            if (textBox != null)
            {
                textBox.BeginChange();
            }

            var blocksToRemove = new List <Block>();

            foreach (var block in _doc.Blocks)
            {
                var para = block as Paragraph;
                if (para != null && para.Inlines.Count == 1)
                {
                    var run = para.Inlines.FirstInline as Run;
                    if (run != null && run.Text == "")
                    {
                        blocksToRemove.Add(block);
                    }
                }
            }

            foreach (var block in blocksToRemove)
            {
                _doc.Blocks.Remove(block);
            }

            // End the undo command
            if (textBox != null)
            {
                textBox.EndChange();
            }
        }
Ejemplo n.º 2
0
        public void UniteLines()
        {
            // Set start an undo command if we can
            TextBoxBase textBox = _doc.Parent as TextBoxBase;

            if (textBox != null)
            {
                textBox.BeginChange();
            }


            var       blocksToRemove = new List <Block>();
            Paragraph lastPara       = null;
            var       block          = _doc.Blocks.FirstBlock;

            while (block != null)
            {
                var para = block as Paragraph;
                if (para != null)
                {
                    if (para.Inlines.Count == 1)
                    {
                        var run = para.Inlines.FirstInline as Run;
                        if (run != null && run.Text.Trim() == "")
                        {
                            lastPara = para;
                            block    = block.NextBlock;
                            continue;
                        }
                    }
                    if (para.Inlines.Count >= 1)
                    {
                        if (lastPara == null)
                        {
                            lastPara = para;
                        }
                        else
                        {
                            para.ContentStart.GetInsertionPosition(LogicalDirection.Forward).InsertTextInRun(" ");
                            var inlines = para.Inlines.Take(para.Inlines.Count);

                            lastPara.Inlines.AddRange(inlines);
                            blocksToRemove.Add(para);
                        }
                    }
                }
                block = block.NextBlock;
            }


            foreach (var item in blocksToRemove)
            {
                _doc.Blocks.Remove(item);
            }

            // End the undo command
            if (textBox != null)
            {
                textBox.EndChange();
            }
        }