我的应用程序中有一个RichTextBox。我需要处理这个RichTextBox的TextChange事件。有两种情况可以改变文本:
我如何单独区分这两个事件?
void SegFileDataContentChanged(object sender, EventArgs e)
{
if (EditorTabcontrol.SelectedIndex != -1)
{
try
{
TabItem selectedTabItem = tabItemList.ElementAt(EditorTabcontrol.SelectedIndex);
SegmentFile selectedSegFile = segFileList.ElementAt(EditorTabcontrol.SelectedIndex);
if (!selectedTabItem.Header.ToString().Contains('*'))
selectedTabItem.Header = selectedTabItem.Header + "*";
selectedSegFile.DataContentChanged = true;
//update dataContent to reflect lastest rtb.text
RichTextBox selectedRTB = rtbList.ElementAt(EditorTabcontrol.SelectedIndex);
selectedSegFile.DataContent = new TextRange(selectedRTB.Document.ContentStart, selectedRTB.Document.ContentEnd).Text;
}
catch (Exception ex)
{
MessageBox.Show("SegFileDataContentChanged", "SegFileDataContentChanged Error", MessageBoxButton.OK);
MessageBox.Show("Unknown Exception Thrown: " + "\n Type: " + ex.GetType().Name + "\n Message: " + ex.Message);
}
}
else
{
MessageBox.Show("No file open", "No File Open Error", MessageBoxButton.OK);
}
}