silverlight – 在TextBox中获取插入位置

silverlight – 在TextBox中获取插入位置,第1张

概述如何在TextBox控件中的可见客户端区域中获取插入位置(x,y)?我需要在文本框中添加自动完成功能. 我找到了solution for WPF,但它无法在Silverlight中应用. public class AutoCompleteTextBox : TextBox{ public Point GetPositionFromCharacterIndex(int index) 如何在TextBox控件中的可见客户端区域中获取插入位置(x,y)?我需要在文本框中添加自动完成功能.

我找到了solution for WPF,但它无法在Silverlight中应用.

解决方法
public class autoCompleteTextBox : TextBox{    public Point GetpositionFromCharacterIndex(int index)    {        if (textwrapPing == textwrapPing.Wrap) throw new NotSupportedException();        var text = Text.Substring(0,index);        int lastNewlineIndex = text.LastIndexOf('\r');        var leftText = lastNewlineIndex != -1 ? text.Substring(lastNewlineIndex + 1) : text;        var block = new TextBlock                        {                            FontFamily = FontFamily,FontSize = FontSize,FontStretch = FontStretch,FontStyle = FontStyle,FontWeight = FontWeight                        };        block.Text = text;        double y = block.ActualHeight;        block.Text = leftText;        double x = block.ActualWIDth;        var scrollVIEwer = GetTemplateChild("ContentElement") as ScrollVIEwer;        var point = scrollVIEwer != null                        ? new Point(x - scrollVIEwer.HorizontalOffset,y - scrollVIEwer.VerticalOffset)                        : new Point(x,y);        point.X += borderThickness.left + padding.left;        point.Y += borderThickness.top + padding.top;        return point;    }}
总结

以上是内存溢出为你收集整理的silverlight – 在TextBox中获取插入位置全部内容,希望文章能够帮你解决silverlight – 在TextBox中获取插入位置所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1005339.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存