The line break symbol (Shift+Enter) is treated as a text character and it gets measured in the document position calculations executed when you click at the end of the document (somewhere after the line break symbol which ends the line).
This causes two visual issues. The first one is that the caret goes after the line break symbol, which means that when ShowFormattingSymbols is False an empty space (non-existing in the document) is added at the end of the line. Even if ShowFormattingSymbols=true and the line break symbol gets display, it is not expected for ,the caret to get positioned after the symbol.
The second issues is that, when you start typing after you click at the end of the line, the caret position is corrected, but this leads to a jumps of the caret with one character to the left, which brings an unpleasant visual glitch.
To work this around, you can create a custom MouseSelectionHandler and override its RegisterDocumentMouseDown method. This will allow you to check if the caret is placed after the line break symbol and manually update the caret position if that is the case.
public class CustomMouseSelectionHandler : MouseSelectionHandler
{
private IDocumentEditorPresenter presenter;
private RadDocument document;
public CustomMouseSelectionHandler(RadDocument document, IDocumentEditorPresenter presenter)
: base(document, presenter)
{
this.presenter = presenter;
this.document = document;
}
public override void RegisterDocumentMouseDown(bool ctrlPressed, bool shiftPressed, Point position, UIElement originalSource = null, SourceType source = SourceType.Mouse)
{
base.RegisterDocumentMouseDown(ctrlPressed, shiftPressed, position, originalSource, source);
var box = this.document.CaretPosition.GetCurrentSpanBox();
if (box != null && box.AssociatedSpan.Text == "¬")
{
document.CaretPosition.MoveToCurrentLineEnd();
}
}
} this.richTextBox.Loaded += (s, args) =>
{
var presenter = (DocumentPresenterBase)this.richTextBox.ActiveEditorPresenter;
presenter.MouseSelectionHandler = new CustomMouseSelectionHandler(this.richTextBox.Document, presenter);
};
ArgumentException occurs when using the voice typing feature of Windows (started with the Windows Key + H key combo) to convert speech to text in RadRichTextBox.
Exception stacktrace:
System.ArgumentException: 'Requested distance is outside the content of the associated document.'PresentationFramework.dll!System.Windows.Documents.TextPointer.TextPointer(System.Windows.Documents.TextContainer textContainer, int offset, System.Windows.Documents.LogicalDirection direction) PresentationFramework.dll!System.Windows.Documents.TextContainer.CreatePointerAtOffset(int offset, System.Windows.Documents.LogicalDirection direction) PresentationFramework.dll!System.Windows.Documents.TextParentUndoUnit.Do() PresentationFramework.dll!MS.Internal.Documents.UndoManager.Redo(int count) PresentationFramework.dll!System.Windows.Documents.TextStore.RedoQuietly(int count) PresentationFramework.dll!System.Windows.Documents.TextStore.SetFinalDocumentState(MS.Internal.Documents.UndoManager undoManager, System.Collections.Stack imeChangeStack, int appChangeCount, int imeSelectionAnchorOffset, int imeSelectionMovingOffset, int appSelectionAnchorOffset, int appSelectionMovingOffset) PresentationFramework.dll!System.Windows.Documents.TextStore.HandleCompositionEvents(int previousUndoCount) PresentationFramework.dll!System.Windows.Documents.TextStore.GrantLockWorker(MS.Win32.UnsafeNativeMethods.LockFlags flags) PresentationFramework.dll!System.Windows.Documents.TextStore.RequestLock(MS.Win32.UnsafeNativeMethods.LockFlags flags, out int hrSession)
FormatException is thrown during the import of a table coming from a docx document when the application culture is "sv-SE". This happens when the column width in the document is a floating point number (ex: 120.65). The Swedish culture uses "," as decimal separator and " " as the number group separator, which makes any invariant decimal value (like 120.65) invalid during standard parsing (ex: float.Parse("120.65")).
Stacktrace:
FormatException: The input string '4514.5' was not in the correct format. at System.Single.Parse(String s) Telerik.Windows.Controls.RichTextBox.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.TableImporter.ImportTableGrid(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Parsing.Style style) Telerik.Windows.Controls.RichTextBox.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.TableImporter.Import(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Parsing.Style parentStyle) Telerik.Windows.Controls.RichTextBox.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.MainDocumentImporter.BuildTable(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Parsing.Style parentStyle) Telerik.Windows.Controls.RichTextBox.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.MainDocumentImporter.BuildBody() Telerik.Windows.Controls.RichTextBox.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.MainDocumentImporter.BuildDocument() Telerik.Windows.Controls.RichTextBox.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.MainDocumentImporter.Import()Telerik.Windows.Controls.RichTextBox.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxImporter.ReadXmlContentFromPackage(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxPartImporterBase importer) Telerik.Windows.Controls.RichTextBox.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxImporter.ReadXmlContentAndRelationsFromPackage(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxPartImporterBase importer) Telerik.Windows.Controls.RichTextBox.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxImporter.Import() Telerik.Windows.Controls.RichTextBox.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.DocxFormatProvider.Import(System.IO.Stream input)
To work this around, switch to InvariantCulture during the import and return the original culture after that.
var cultureCache = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
var provider= new DocxFormatProvider();
rtb.Document = provider.Import(stream);
Thread.CurrentThread.CurrentCulture = cultureCache;
Thread.CurrentThread.CurrentUICulture = cultureCache;
Working with the RadContextMenu that comes from the RadRichTextBoxUI, when having analytics enabled, produces a NullReferenceException.
Manually set the Menu property on the PreviewMouseLeftButtonUp event of the RadMenuItem:
static MainWindow()
{
EventManager.RegisterClassHandler(typeof(RadMenuItem), PreviewMouseLeftButtonUpEvent, new MouseButtonEventHandler(OnRadMenuItemPreviewMouseLeftButtonUp), true);
}
private static void OnRadMenuItemPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
RadMenuItem radMenuItem = (RadMenuItem)sender;
RadContextMenu radContextMenu = radMenuItem.ParentOfType<RadContextMenu>();
if (radContextMenu != null)
{
PropertyInfo menuPropertyInfo = radMenuItem.GetType().GetProperty("Menu", BindingFlags.Public | BindingFlags.Instance);
if (menuPropertyInfo != null)
{
MethodInfo setMethod = menuPropertyInfo.GetSetMethod(true);
if (setMethod != null)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
setMethod.Invoke(radMenuItem, new object[] { radContextMenu });
}), System.Windows.Threading.DispatcherPriority.Background);
}
}
}
}
RichTextBox: Bullet list with several levels is not viewed correctly in WordPad.
In Word, this works as expected. When the document is imported into RadRichTextBox, this works as well.
The RichTextBox internal logic that imports .docx documents (DocxFormatProvider) doesn't support elements that don't need direct content, but have both start and end tags. Instead such elements should use self-closing tags.
For example, instead of <w:vertAlign w:val="baseline"></w:vertAlign> it should be <w:vertAlign w:val="baseline"/>
When such element is read during import, issues may occur. Two main known issues here are with the w:vertAlign and Relationship tags.
Using
<w:vertAlign w:val="baseline"></w:vertAlign> instead of
<w:vertAlign w:val="baseline"/> throws NullReferenceException with the following stack trace:
System.NullReferenceException: 'Object reference not set to an instance of an object.' Telerik.Windows.Documents.FormatProviders.OpenXml.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlHelper.ConvertStringToBaselineAlignment(string value) Line 168 C# Telerik.Windows.Documents.FormatProviders.OpenXml.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.SpanStyleImporter.ReadBaselineAlignment(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Parsing.Style style) Line 243 C# Telerik.Windows.Documents.FormatProviders.OpenXml.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.SpanStyleImporter.ReadStyle(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Parsing.Style style) Line 88 C# Telerik.Windows.Documents.FormatProviders.OpenXml.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.StyleDefinitionsImporter.ReadSpanStyleProperties(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Parsing.Style style) Line 278 C# Telerik.Windows.Documents.FormatProviders.OpenXml.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.StyleDefinitionsImporter.ReadStyle() Line 188 C# Telerik.Windows.Documents.FormatProviders.OpenXml.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.StyleDefinitionsImporter.Import() Line 67 C# Telerik.Windows.Documents.FormatProviders.OpenXml.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxImporter.ReadXmlContentFromPackage(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxPartImporterBase importer) Line 430 C# Telerik.Windows.Documents.FormatProviders.OpenXml.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxImporter.ReadXmlContentAndRelationsFromPackage(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxPartImporterBase importer) Line 406 C# Telerik.Windows.Documents.FormatProviders.OpenXml.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxImporter.Import() Line 190 C# Telerik.Windows.Documents.FormatProviders.OpenXml.dll!Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.DocxFormatProvider.Import(System.IO.Stream input) Line 147 C# Telerik.Windows.Documents.dll!Telerik.Windows.Documents.FormatProviders.DocumentFormatProviderBase.Import(byte[] input) Line 90 C#
Using
<Relationship Id="rId00004" Target="styles.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"></Relationship> instead of
<Relationship Id="rId00004" Target="styles.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"/> throws KeyNotFoundException with the following stack trace:
KeyNotFoundException: The given key was not present in the dictionary.
System.ThrowHelper.ThrowKeyNotFoundException() in ThrowHelper.cs
System.Collections.Generic.Dictionary<TKey, TValue>.this[TKey].get(TKey) in Dictionary.cs
Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.PartRelationsImporter.GetRelationByID(string) in PartRelationsImporter.cs
Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxImporter.GetRelationByID(string) in DocxImporter.cs
Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.MainDocumentImporter.BuildSection() in MainDocumentImporter.cs
Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.MainDocumentImporter.BuildBody() in MainDocumentImporter.cs
Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.MainDocumentImporter.BuildDocument() in MainDocumentImporter.cs
Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.MainDocumentImporter.Import() in MainDocumentImporter.cs
Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxImporter.ReadXmlContentFromPackage(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxPartImporterBase) in DocxImporter.cs
Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxImporter.ReadXmlContentAndRelationsFromPackage(Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxPartImporterBase) in DocxImporter.cs
To work this around, import the document with the WordsProcessing library. If you need to display it in RadRichTextBox, you can export it again using the WordsProcessing library. This will normalize the tags. Then import it again using the RadDocument's DocxFormatProvider.
var dplDocxFormatProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
RadFlowDocument flowDocument = dplDocxFormatProvider.Import(File.ReadAllBytes("../../../test.docx"), null);
var docBytes = dplDocxFormatProvider.Export(flowDocument, null);
File.WriteAllBytes("../../../modified-doc.docx", docBytes);
var rtbDocxFormatProvider= new Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.DocxFormatProvider();
RadDocument document = rtbDocxFormatProvider.Import(File.ReadAllBytes("../../../modified-doc.docx"));
Bold/Italic does not work for some font styles.
This might be a framework limitation in WPF: https://www.telerik.com/forums/some-fonts-are-not-able-to-bold-italic
Sample fonts list:
Can be reproduced in the demo:
In our processes, it is very important to know if a change happened before or after another action. If all the revisions have zero seconds, it's impossible to determine the order of the changes when they happened in the same minute.
This is not a new bug introduce in SP2: it was there in SP1.