Is there a way to group or temporarily disable the undo history for a RichTextBox?

后端 未结 2 1096
清歌不尽
清歌不尽 2021-02-19 07:24

I\'m currently wrestling with Tables inside RichTextBoxs in WPF. In WPF, tables don\'t have rows and columns, they just have rows, each having a certain number of cells. When a

2条回答
  •  悲&欢浪女
    2021-02-19 07:51

    If you want to group undo actions (rather than disable undo entirely), you can group a set of programmatic changes via TextBoxBase.BeginChange() then, after making the changes, TextBoxBase.EndChange(), i.e.:

            richTextBox.BeginChange();
            try
            {
                // Add column
    
                // For each row, add a cell to the column.
            }
            finally
            {
                richTextBox.EndChange();
            }
    

    Or, equivalently, you can call TextBoxBase.DeclareChangeBlock() inside a using statement:

            using (richTextBox.DeclareChangeBlock())
            {
                // Add column
    
                // For each row, add a cell to the column.
            }
    

提交回复
热议问题