RichEditBox (UWP) ignores font and foreground when setting Rtf text

后端 未结 1 409
一整个雨季
一整个雨季 2021-01-27 00:00

I\'m working with a RichEditBox and I\'m having some problems saving and restoring the Rtf text.

Here\'s a sample Rtf text I\'ve exported, as you can see th

相关标签:
1条回答
  • 2021-01-27 00:43

    This issue currently cannot be reproduced in newest windows 10 build 14393 by code as follows:

    XAML Code

    ... mc:Ignorable="d" Loaded="Page_Loaded">
    <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
       <RichEditBox x:Name="EditBox"  Height="400" Margin="40"   >
       </RichEditBox> 
    </StackPanel>
    

    Code behind:

    private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        string myRtfString = @"{\rtf1\fbidis\ansi\ansicpg1252\deff0\nouicompat\deflang1040
     {\fonttbl{\f0\fnil\fcharset0 Segoe UI;}
     {\f1\fnil\fcharset0 Brush Script MT;}
     {\f2\fnil\fcharset0 Impact;}
     {\f3\fnil Segoe UI;}}
     {\colortbl ;\red9\green105\blue192;\red0\green0\blue0;\red76\green152\blue25;\red208\green52\blue56;}
     {\*\generator Riched20 10.0.14393}\viewkind4\uc1 
     \pard\ltrpar\tx720\cf1\b\i\f0\fs23 Test\cf2\b0\i0\par
     \pard\ltrpar\li320\qc\tx720\cf3\strike\f1\fs40 Some color\cf2\strike0\f0\fs23\par
     \pard\ltrpar\tx720\cf4\f2 Hello!\cf2\f0\par
     \f3\par
     \f0\lang1033\par   
     \f3\par
     \par
     \pard\ltrpar\tx720\fs23\par
     }";
        EditBox.Document.SetText(TextSetOptions.FormatRtf, myRtfString);
    } 
    

    If you still want a workaround in your environment, please try to find the following code which is under “Focused ViewState” in the style of RichEditTextBox and comment it out. For more details about this please reference this thread.

     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentElement">
         <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlForegroundChromeBlackHighBrush}"/>
     </ObjectAnimationUsingKeyFrames>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="RequestedTheme" Storyboard.TargetName="ContentElement">
        <DiscreteObjectKeyFrame KeyTime="0" Value="Light"/>
    </ObjectAnimationUsingKeyFrames>
    

    And the result on my side:

    0 讨论(0)
提交回复
热议问题