0
4

2 回答 2

1

Is there any workaround to prevent that the font size is set back to 10.5 in any case?

For your requirement, you could force font size to 20 when you press Shift+Right. Please refer the following code.

private void HandleRichEditBox_SelectionChanged(object sender, RoutedEventArgs e)
{
    FontSizeBlock.Text = "FontSize: " + Editor.Document.Selection.CharacterFormat.Size;
    if (Editor.Document.Selection.CharacterFormat.Size == 10.5)
    {
        Editor.Document.Selection.SetRange(0, 1);
        Editor.Document.Selection.CharacterFormat.Size = 20;
    }
}
于 2020-06-01T13:38:51.923 回答
1

When further investigating my problem, I noted that my issue doesn't occur when there has already been some text in the RichEditBox which was deleted.

Therefore, I have tried to programmatically append, select and remove characters in the Page_Loaded-handle, and this approach worked for me.

private void Page_Loaded(object sender, RoutedEventArgs e) {
    // set any character
    Editor.Document.SetText(Windows.UI.Text.TextSetOptions.None, "a");
    Editor.Document.Selection.Expand(Windows.UI.Text.TextRangeUnit.Paragraph);
    Editor.Document.Selection.CharacterFormat.Size = 20;
    Editor.Document.SetText(Windows.UI.Text.TextSetOptions.None, "");

}
于 2020-06-02T14:24:07.987 回答