如何在 WPF RichTextBox 中底部对齐文本
如何在 RichTextBox 中底部对齐文本?貌似控件不直接支持。所以我正在寻找模仿它的方法。理想情况下,我会将控件的边界固定,并将文本结尾与底部对齐。
How I can bottom align text in RichTextBox? It seems that control doesn't support it directly. So I am looking for ways to emulate it. Ideally I would have the boundary of the control fixed and end of text aligned with the bottom.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文本来自 TextBoxBase 的默认控件模板内名为 PART_ContentHost 的 ScrollViewer,该模板由 RichTextBox 包装。您应该覆盖控件模板,并让 ScrollViewer 将其 VerticalAlignment 声明为 Bottom,或者将其模板绑定到 VerticalContentAlignment。
下面,我做了后者。这是从 Blend 中提取的默认控制模板的修改版本。我所做的唯一更改是将 VerticalAlignment="{TemplateBinding VerticalAlignment}" 添加到 ScrollViewer。
(另请注意,它引用了 Microsoft_Windows_Themes,定义为 xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes; assembly=PresentationFramework.Aero"
我不确定如果 Aero 不在用户的计算机上,这将如何工作)
然后,要使用它,只需说:
The text comes from a ScrollViewer named PART_ContentHost inside the default control template for the TextBoxBase which is wrapped by the RichTextBox. You should override the control template and either have the ScrollViewer declare its VerticalAlignment to be Bottom, or have it template bind to the VerticalContentAlignment.
Below, I've done the latter. This is a modified version of the default control template as pulled from Blend. The only change I've made is to add VerticalAlignment="{TemplateBinding VerticalAlignment}" to the ScrollViewer.
(Also note that it references Microsoft_Windows_Themes which is defined as xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
I am unsure how this will work if Aero is not on the user's machine)
Then, to use it, simply say: