WPF中的RichTextBox对齐问题 [英] RichTextBox alignment problem in WPF

查看:599
本文介绍了WPF中的RichTextBox对齐问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在WPF中处理RichTextBox.我在Richtextbox上方放置了一个工具栏.该工具栏由粗体,斜体,下划线,左,中,右,ColorDialog等组成.
一切都很好.但是这里的问题是,
如果我将字体大小更改为24,则将其变粗,然后居中.
现在将其突出显示并将颜色更改为红色.对齐方式将变为左",即使居中"仍突出显示.


在这里如何保持当前文本对齐状态?即使我使用colordialog更改了文本的颜色,其对齐方式也应保持不变.它不应该向左移动.
请任何人尽快帮助我.
谢谢
问候,
Santhosh

Hello Everyone,
Am working on RichTextBox in WPF. I placed a tool bar which is above to the richtextbox. that toolbar consists of Bold,Italic,UnderLine,Left,Center,Right,ColorDialog etc.
Everything is workinfg fine. But the problem here is,
if i change the font size to 24, make it bold and then Center it.
Now highlight it and change the color to red. The justification will change to Left, eventhough Centered is still highlighted.


How to maintain the status of current text alignment here? Even though i change the color of text using colordialog,the alignment of the should remain same. It should not move to Left.
Plz anyone help me onthis asap.
thank you,
Regards,
Santhosh

推荐答案

您在做

richtextbox.SelectionColor = Color.Red;

我认为,当您更改其颜色时,richtextbox会以某种方式将SelectionFont修改为其默认值.

仔细检查您的代码,我认为它应该可以正常工作.
Are you doing

richtextbox.SelectionColor = Color.Red;

I think somehow the richtextbox is modifying the SelectionFont to its default when you change its color.

Check your code minutely, it should be working I think.


您需要使用

range.ApplyPropertyValue(TextElement.ForegroundProperty,b1);
you need to use

range.ApplyPropertyValue(TextElement.ForegroundProperty, b1);


您需要使用

range.ApplyPropertyValue(TextElement.ForegroundProperty,b1);
you need to use

range.ApplyPropertyValue(TextElement.ForegroundProperty, b1);


这篇关于WPF中的RichTextBox对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆