private void DataContext_XmlDecode(IBasicData obj) { this.Dispatcher.Invoke(new Action(() => { XmlEncoder xmlEncoder = new XmlEncoder(); string startString = txt_xmlViewer.Text.Substring(0, txt_xmlViewer.CaretIndex); string finalString = txt_xmlViewer.Text.Substring(txt_xmlViewer.CaretIndex); txt_xmlViewer.Text = string.Format("{0}{1}{2}\n\r", startString, xmlEncoder.xmlEncode1(obj), finalString); //txt_xmlViewer.AppendText(XmlEncode.xmlEncode((sender as MenuItemData).Data)+"\r\n"); })); }