I implemented a control with a part RichTextEditor. Now i want my view model to be notified of changes in said control, whenever the TextChanges. I managed to Notify my ViewModel by saving the xaml of the RichTextEditor to the DependencyProperty of my Control, but when loading another ViewModel I get an exception.
Managed Debugging Assistant 'FatalExecutionEngineError'
Message=Managed Debugging Assistant 'FatalExecutionEngineError' :
'The runtime has detected a serious error. error address:
"0x6204610f" in Thread "0x3f98".
Fehlercode: 0x80131623.
This error could be a problem in the CLR or
in the unsafe or unverifiable parts of the user code.
Common causes of this bug are Marshaller errors for COM interop or
PInvoke, which can damage the stack. '
This was translated with google.
This works fine when I do it whenever the RichTextEditor loses focus, but doesnt when I do it whenever the Editors Text changes.
private void RichTextEditor_TextChanged(object sender, TextChangedEventArgs e)
{
RichTextBox rtb = sender as RichTextBox;
DocumentText = rtb.Document;
DocumentXaml = XamlWriter.Save(rtb.Document);
}
this leads to an exception here in OnDocumentXamlChanged:
StringReader stringReader = new StringReader(e.NewValue.ToString());
XmlReader xmlReader = XmlReader.Create(stringReader);
richTextBox.Document = (FlowDocument)XamlReader.Load(xmlReader);
but this works fine:
private void RichTextEditor_LostFocus(object sender, RoutedEventArgs e)
{
RichTextBox rtb = sender as RichTextBox;
DocumentText = rtb.Document;
DocumentXaml = XamlWriter.Save(rtb.Document);
selectionOffsets = GetSelectionOffsetsRTB(rtb);
IsFocusChanged = false;
this.UpdateCommandsEnabledState();
}
I have no idea what could cause this Exception im guessing im using the built in functions wrong in any way? Thanks in advance!
User contributions licensed under CC BY-SA 3.0