如何在WPF中获取richtextbox最后一个词是否为BringIntoView(显示)? [英] How to get whether richtextbox last word is BringIntoView(shown) or not in WPF?

查看:53
本文介绍了如何在WPF中获取richtextbox最后一个词是否为BringIntoView(显示)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 wpf 工作,我有一个包含一些内容的富文本框.如果内容超出富文本框,我想隐藏底部边框.如果富文本框中的内容我想显示底部边框.现在我正在使用下面的代码将超出的内容带到富文本框中查看.

i am working in wpf,i have a richtextbox with some contents.if the contents are exceeded to richtextbox i want to hide bottom border.if the content within the richtextbox i want to show the bottom border.Now i am using the below code to bring the exceeded content to view in richtextbox.

 FrameworkContentElement fce = (startPos.Parent as FrameworkContentElement);
            if (fce != null)
            {
                fce.BringIntoView();
            }

但我想显示底部边框,一旦显示在富文本框中的最后一个字.如何实现?

But i want to display the bottom border,once the last word shown in that richtextbox.How to achieve this?

注意:我已经知道如何动态显示底部边框.但我想知道最后一个单词是否显示在富文本框中?

Note: I already known how to show bottom border dynamically.but i want to know last word are displayed within the richtextbox or not?

问候阿俊

推荐答案

我可以给你提供一种检查字符左上角是否可见的方法.创建一个类库Tools,内容如下:

I can provide you with a method to check whether the upper left corner of a character is visible or not. Create a class library Tools with the following content:

public class ToolsRtb
{
    public static bool PositionVisibleIs(RichTextBox rtb, TextPointer pos)
    {
        // Rectangle around the character to check
        Rect r = pos.GetCharacterRect(LogicalDirection.Forward);

        // Upper left corner of the rectangle ...
        Point upperLeftCorner = r.Location;

        HitTestResult result = VisualTreeHelper.HitTest(rtb, upperLeftCorner);

        // ... is visible?
        if (result != null)
            return true;
        else
            return false;
    }   
}

请注意,PositionVisibleIs(...) 是一个静态方法,并非专用于特定对象.在包含您的 RichTextBox 的窗口的代码隐藏文件中,使用如下方法:

Note that PositionVisibleIs(...) is a static method and not dedicated to a specific object. In the code behind file of the window which contains your RichTextBox use the method like this:

// Is the last character of the current document visible?
if (ToolsRtb.PositionVisibleIs(rtb, rtb.Document.ContentEnd) == true)
{
    ...
}

希望这会有所帮助.

这篇关于如何在WPF中获取richtextbox最后一个词是否为BringIntoView(显示)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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