WPF Richtextbox加载的文档段落边框

时间:2020-08-19 16:46:46

标签: c# wpf xaml

我有一个UserControl,基本上包裹了一个RichTextBox,看起来像这样:

<UserControl x:Class="Installers.Ui.Views.Controls.RichTextBox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary Source="../../Theme/ElementsTheme.xaml"></ResourceDictionary>
    </UserControl.Resources>
    <RichTextBox x:Name="MyRichTextbox" Background="{StaticResource BackgroundColorBrush}" Foreground="{StaticResource GrayColorBrush}" BorderThickness="0" BorderBrush="Transparent">
            
    </RichTextBox>
</UserControl>

我在后面的代码中有一些样式,如下所示:

      public override void OnApplyTemplate()
      {
           base.OnApplyTemplate();

           var text = GetValue(RTFTextProperty).ToString();
           var memoryStream = new MemoryStream(ASCIIEncoding.Default.GetBytes(text));
           MyRichTextbox.Selection.Load(memoryStream, DataFormats.Rtf);
           
           MyRichTextbox.IsReadOnly = IsReadOnly;
      }

这是结果:

RichTextBox

现在我的问题是:正如您所看到的,某些文本周围有“框”,如何将它们的颜色更改为背景色,或者如何将其完全删除?

0 个答案:

没有答案
相关问题