【问题标题】:How to get rid of (or match color of) space between RichTextBox and adjacent image如何摆脱 RichTextBox 和相邻图像之间的空间(或匹配颜色)
【发布时间】:2023-03-06 04:43:01
【问题描述】:

所以我有以下 XAML:

<DockPanel Name="dpSchedItem" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" LastChildFill="True">
    <Image DockPanel.Dock="Right" Height="17" Width="17" VerticalAlignment="Top" HorizontalAlignment="Right" Cursor="Hand" Margin="0,0,0,0" Source="Resources\Pencil_Gray.png" MouseUp="Image_MouseUp" />
    <RichTextBox DockPanel.Dock="Left" Name="rtbText" Margin="0,0,0,0" VerticalScrollBarVisibility="Auto" BorderThickness="0" BorderBrush="Transparent" IsReadOnly="True" />
</DockPanel>

我在代码中向 RichTextBox 添加内容:

rtbText.BorderBrush = BackgroundColor
Dim p As New Paragraph
p.Inlines.Add(New Bold(New Run(SO & If(Title = "", "", " - " & Title))))
rtbText.Document = New FlowDocument(p) With {.Background = BackgroundColor, .PagePadding = New Thickness(0.0)}

但它是这样渲染的:

我尝试覆盖控件模板,就像它为按钮显示 here 一样,但 RTB 没有相同的内容属性。从另一篇文章中,我得到了将 FlowDocument 的 PagePadding 厚度设置为 0 的想法,但这并没有得到我想要的结果。

我希望该空间(边框或边距,或其他任何内容)像其他所有内容一样是绿色的。

【问题讨论】:

    标签: wpf wpf-controls


    【解决方案1】:

    目前尚不清楚保持网格/页面是否为绿色,但将控件背景颜色设为Transparent,直到实现全绿色,例如:

    <DockPanel Background="Transparent"...>
       <RichTextBox Background="Transparent" BorderBrush="Transparent" ...>
    

    或者将DockPanel的背景设为GreenRichTextBox的背景设为Transparent

    【讨论】:

    • >或者将 DockPanel 的背景设为绿色,将 RichTextBox 背景设为透明 - 这很有效。 Facepalm 因为我自己没看到。谢谢!
    • @tolsen64 我们都去过那里,它总是的事情。很高兴能提供帮助。
    猜你喜欢
    • 2020-10-06
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2015-02-05
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 2011-01-31
    相关资源
    最近更新 更多