How to limit to max 83 Chars per single line in RichTextBox

ⅰ亾dé卋堺 提交于 2019-12-11 16:12:47

问题


Im trying to make a recreation of MSWord using WPF RichTextBox and Toolbar, so one of the recently issues is the following:

In MSWord document...

...with Font Family Times New Roman, 11, Justify a single line contains 95 Chars ...with Font Family Times New Roman, 11, Justify, Bold a single line contains 83 Chars

about margins It will be more recommended to work with margins or limit chars per line? Cause when user inputs are , . or anothers ASCII wich size is shorter than others ones, the max chars in single line "Changes". So if use margins is most propertly - how the WPF RichTextBox manage margins ?

Thanks!


回答1:


Trying to limit characters per line sounds like a nightmare to me. You're better off getting rid of the default ControlTemplate for RichTextBox so you just have the text, then setting the Margin on your RichTextBox so the text "floats" in the middle:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ScrollViewer>
        <RichTextBox Margin="30,0">
            <RichTextBox.Template>
                <ControlTemplate TargetType="{x:Type RichTextBox}">
                    <Border x:Name="PART_ContentHost" Margin="2" Background="Transparent" BorderBrush="Transparent"/>
                </ControlTemplate>
            </RichTextBox.Template>
        </RichTextBox>
    </ScrollViewer>
</Grid>


来源:https://stackoverflow.com/questions/639634/how-to-limit-to-max-83-chars-per-single-line-in-richtextbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!