简体   繁体   中英

Draw a vertical line on a wpf RichTextBox

I have a custom RichTextBox class that I want to draw a vertical line on. (The idea is that it will show a "Char Limit".)

I have tried overriding OnRender, but that did not draw anything.

I have read of using Adorners, but they update how text looks. (I just want to draw a line, nothing related to the text.)

Is there a way to just draw a vertical line from the top to the bottom?

One quick way:

<Grid x:Name="Container" Height="100">
    <RichTextBox/>
    <Line Stroke="Aqua" X1="160" X2="160" Y1="0" Y2="{Binding Path=Height,ElementName=Container}" IsHitTestVisible="False"/>
</Grid>

IsHitTestVisible="False" is just incase they click right on the line, don't want that to eat the mouse click.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM