如何在RichTextBox中对齐文本?看来控制不直接支持它。所以我正在寻找方法来模拟它。理想情况下,我会将控件的边界固定,文本的末尾与底部对齐。如何在WPF RichTextBox中对齐文本
2
A
回答
0
该文本来自名为PART_ContentHost的ScrollViewer,该文本位于由RichTextBox包装的TextBoxBase的默认控件模板内。您应该重写控件模板,并让ScrollViewer将VerticalAlignment声明为Bottom,或者将模板绑定到VerticalContentAlignment。
下面,我做了后者。这是从Blend中提取的默认控制模板的修改版本。我所做的唯一更改是向ScrollViewer添加VerticalAlignment =“{TemplateBinding VerticalAlignment}”。
(另请注意,它引用其定义为的xmlns Microsoft_Windows_Themes:Microsoft_Windows_Themes =“CLR的命名空间:Microsoft.Windows.Themes;装配= PresentationFramework.Aero”
我不确定如何,如果Aero是这将工作而不是用户的机器
<Style x:Key="BottomAlignedTextBoxBaseStyle"
TargetType="TextBoxBase"
BasedOn="{StaticResource {x:Type TextBoxBase}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Microsoft_Windows_Themes:ListBoxChrome x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" SnapsToDevicePixels="true">
<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Microsoft_Windows_Themes:ListBoxChrome>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
再打开),使用它,简单地说:
<RichTextBox Style="{StaticResource BottomAlignedTextBoxBaseStyle}" VerticalContentAlignment="Bottom" />
相关问题
- 1. 如何在RichTextBox C#中“对齐”文本?
- 2. WPF。如何对齐文本InlineUIContainer内容与外文本的RichTextBox
- 3. 在RichTextBox中对齐数字
- 4. 对齐RichTextBox的
- 5. 如何在WPF中将星号与周围的文本对齐?
- 6. 保存richtextbox文本wpf
- 7. Wpf RichTextBox复制textstyle文本
- 8. RichTextBox中的对齐选项
- 9. WPF TextBlock中的文本垂直对齐
- 10. 如何在WPF RichTextBox中设置纯文本格式
- 11. 如何在中心对齐UISegment文本
- 12. 如何在div中对齐文本?
- 13. 如何在DataGridView列中对齐文本?
- 14. 如何在python中对齐文本
- 15. 如何在Wordpress中对齐文本?
- 16. 如何在android中对齐文本
- 17. 如何在Android Webview中对齐文本?
- 18. WPF中的文本包装FlowDocumentScrollViewer/RichTextBox
- 19. wpf richtextbox中的文本自动替换
- 20. 替换WPF中的文本Richtextbox
- 21. 如何对齐WPF菜单项中的文本?
- 22. 如何从RichTextBox中获取WPF中的所有文本
- 23. 如何设置WPF C#中richtextbox中文本的行间距?
- 24. 左右对齐richtextbox c#
- 25. 如何对齐文本?
- 26. 如何对齐此文本?
- 27. 如何对齐文本框?
- 28. 如何对齐此文本?
- 29. 如何对齐文本框
- 30. 如何在运行时在一个WPF按钮中居中对齐文本?
我试图改变与WPF Inspector中的财产,这是行不通的!你试过了吗? – Alfa07 2011-06-02 09:37:11
对不起,我在Style的BasedOn属性中有一个拼写错误。现在就试试? – Adrian 2011-06-02 15:43:52