C#:
using System.Collections.ObjectModel;
using System.Windows.Controls;
using System.Windows.Documents;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
public ObservableCollection<Log> Logs { get; set; } = new ObservableCollection<Log>();
private string _oldText = "";
private string _newText = "";
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
private void RichTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
_newText = new TextRange((e.Source as RichTextBox).Document.ContentStart, (e.Source as RichTextBox).Document.ContentEnd).Text;
Logs.Add(new Log { New = _newText, Old = _oldText });
_oldText = _newText;
}
public class Log
{
public string Old { get; set; }
public string New { get; set; }
}
}
}
XAML:
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<RichTextBox TextChanged="RichTextBox_TextChanged"/>
<DataGrid Grid.Row="1" ItemsSource="{Binding Logs}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="Было" Binding="{Binding Old}"/>
<DataGridTextColumn Width="*" Header="Стало" Binding="{Binding New}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
Демонстрация ниже: