将 table 复制到 WPF RichTextBox 丢失边框

Copy table into WPF RichTextBox loosing borders

我用 Table 生成 FlowDocument 并替换 WPF RTF 框中的 Selection

但是插入的 table 对所有单元格使用最后使用的 BorderSettings。如果我将生成的 XAML 加载到 FlowDocumentPageViewer 中,一切看起来都很好。

查看者:

错误的 RTF:

请忽略其他格式,只有 Border 是我的问题,最后的 Border 是下划线,但在 RTF 中它会覆盖所有其他 CellBordersColor 在 table.

代码:

//GetTable returns the Table
FlowDocument tmp_rtf_tabelle_test =new FlowDocument(((Datenblock_Mitte_Tabelle_Typ5)obj).GetTable());
              
TextRange tr_tabelle = new TextRange(tmp_rtf_tabelle_test.ContentStart,tmp_rtf_tabelle_test.ContentEnd);         

MemoryStream ms_tabelle = new MemoryStream();
                       
//if Dataformats XAML or rtf make no difference
tr_tabelle.Save(ms_tabelle, DataFormats.Xaml);                           
                   
rtf_vorschau.Selection.Load(ms_tabelle, DataFormats.Xaml);
ms_tabelle.Close();

这是生成的 XAML:

<Section
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Justify" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="LeftToRight" NumberSubstitution.CultureSource="Text" NumberSubstitution.Substitution="AsCulture" FontFamily="Georgia" FontStyle="Normal" FontWeight="Normal" FontStretch="Normal" FontSize="16" Foreground="#FF000000" Typography.StandardLigatures="True" Typography.ContextualLigatures="True" Typography.DiscretionaryLigatures="False" Typography.HistoricalLigatures="False" Typography.AnnotationAlternates="0" Typography.ContextualAlternates="True" Typography.HistoricalForms="False" Typography.Kerning="True" Typography.CapitalSpacing="False" Typography.CaseSensitiveForms="False" Typography.StylisticSet1="False" Typography.StylisticSet2="False" Typography.StylisticSet3="False" Typography.StylisticSet4="False" Typography.StylisticSet5="False" Typography.StylisticSet6="False" Typography.StylisticSet7="False" Typography.StylisticSet8="False" Typography.StylisticSet9="False" Typography.StylisticSet10="False" Typography.StylisticSet11="False" Typography.StylisticSet12="False" Typography.StylisticSet13="False" Typography.StylisticSet14="False" Typography.StylisticSet15="False" Typography.StylisticSet16="False" Typography.StylisticSet17="False" Typography.StylisticSet18="False" Typography.StylisticSet19="False" Typography.StylisticSet20="False" Typography.Fraction="Normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.EastAsianExpertForms="False" Typography.Variants="Normal" Typography.Capitals="Normal" Typography.NumeralStyle="Normal" Typography.NumeralAlignment="Normal" Typography.EastAsianWidths="Normal" Typography.EastAsianLanguage="Normal" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.StylisticAlternates="0">
    <Table Padding="0,0,0,0" BorderThickness="1,1,1,1">
        <Table.Columns>
            <TableColumn Width="300" />
            <TableColumn Width="419" />
        </Table.Columns>
        <TableRowGroup>
            <TableRow>
                <TableCell ColumnSpan="2" BorderThickness="1,1,1,1" BorderBrush="#FFFF0000">
                    <Paragraph Background="#FFD3D3D3">
                        <Run> 5. Weitere Vorgehensweise</Run>
                    </Paragraph>
                </TableCell>
            </TableRow>
            <TableRow>
                <TableCell Padding="0,0,0,0" BorderThickness="1,0,0,0" BorderBrush="#FF0000FF">
                    <Paragraph LineHeight="1" Margin="0,0,0,0">
                        <Run> Haftung:</Run>
                    </Paragraph>
                </TableCell>
                <TableCell BorderThickness="0,0,0,1" BorderBrush="#FFFFFF00">
                    <Paragraph>
                        <Run>&lt;Bitte wählen&gt;</Run>
                    </Paragraph>
                </TableCell>
            </TableRow>
            <TableRow>
                <TableCell>
                    <Paragraph>
                        <Run> Deckung:</Run>
                    </Paragraph>
                </TableCell>
                <TableCell>
                    <Paragraph>
                        <Run>&lt;Bitte wählen&gt;</Run>
                    </Paragraph>
                </TableCell>
            </TableRow>
            <TableRow>
                <TableCell>
                    <Paragraph>
                        <Run> Plausibilität:</Run>
                    </Paragraph>
                </TableCell>
                <TableCell>
                    <Paragraph>
                        <Run>&lt;Bitte wählen&gt;</Run>
                    </Paragraph>
                </TableCell>
            </TableRow>
            <TableRow>
                <TableCell>
                    <Paragraph>
                        <Run> Zahlung in €:</Run>
                    </Paragraph>
                </TableCell>
                <TableCell>
                    <Paragraph>
                        <Run>0,00</Run>
                    </Paragraph>
                </TableCell>
            </TableRow>
            <TableRow>
                <TableCell>
                    <Paragraph>
                        <Run> Reserve in €:</Run>
                    </Paragraph>
                </TableCell>
                <TableCell>
                    <Paragraph>
                        <Run>0,00</Run>
                    </Paragraph>
                </TableCell>
            </TableRow>
            <TableRow>
                <TableCell>
                    <Paragraph>
                        <Run> Unterlagen folgen:</Run>
                    </Paragraph>
                </TableCell>
                <TableCell>
                    <Paragraph>
                        <Run>&lt;Bitte wählen&gt;</Run>
                    </Paragraph>
                </TableCell>
            </TableRow>
            <TableRow>
                <TableCell ColumnSpan="2">
                    <Paragraph Margin="3,3,3,3">
                        <Run></Run>
                    </Paragraph>
                </TableCell>
            </TableRow>
        </TableRowGroup>
    </Table>
</Section>

更新:我用 Tables 创建了一个 RTF 文件并加载了它们 (FileStream),但结果是一样的。 BorderSettings 迷路了。

根据加载富文本格式(RTF)文档时的问题描述,其中包含table带有彩色边框,边框失去颜色并显示为黑色。

Let suppose the original .rtf document includes the following table with yellow cell borders:

After loading this document to the RichTextBox control the table will look like below:

不幸的是,这是在 WPF RichTextBox 控件中显示 .rtf 使用 Microsft Word 准备的文档的已知限制。

MSDN 社区支持人员写道:

I load the rtf document and displayed in WPF RitchTextBox, it lost part of the format (Open Normal with Word). If you want to open it with WPF RitchTextBox, I recommend using WPF RitchTextBox to save RTF files open to ensure consistent format. You can Load, Edit and Save Rich Text Format in WPF. Some styles may be lost through tool conversion.

有关详细信息,请参阅 Microsoft 站点上的文章:rtf document displayed in RitchTextBox display wrong colors