Silverlight 4 C# - 如何在自定义用户控件的文本位置显示弹出窗口?
我正在尝试在我的应用程序中创建拼写检查功能,该功能将在列表框中弹出可能的更正信息。
我还没有找到任何关于如何创建然后引用自定义用户控件,或者如何获取特定文本片段的坐标的任何合适的文档。
有没有人有一些示例代码,介绍如何制作带有弹出窗口的自定义用户控件,以及如何从主应用程序引用并显示该弹出窗口?另外,计算出文本框中某些选定文本的 X 和 Y 偏移量也很棒,这样我就可以将弹出窗口放置在拼写错误的右侧和正下方。
提前致谢!
-苏塔
I'm trying to make a spellcheck function in my application that will show a pop-up of possible corrections in a listbox.
I've not found any decent documentation on how to create and then reference a custom usercontrol, or how to get the coordinates of a specific piece of a bit of text.
Does anybody have some example code on how to make a custom usercontrol with a popup in it and how to then reference and show that popup from the main app? Also figuring out the X and Y offsets of some selected text in a textbox would be great also so I can position the popup to the right and just below the spelling error.
Thanks in advance!
-Sootah
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您有一个名为 richtextbox 的 richttextbox 控件。然后,当您选择一些文本并按下按钮时,您可以创建一个弹出控件,其中包含您的自定义用户控件。然后确定文本相对于视觉根的位置,瞧:)
然后在您想要的解决方案中将选择手动设置为错误的文本。
http://strugglesofacoder.blogspot.com /2011/02/show-popup-under-text-in-rich-textbox.html
Imagine you have a richttextbox control called richtextbox. Then when you select some text and press a button you can create a popup control with your custom UserControl in it. Then determin the position of the text relative to your visual root and voila :)
Then in the solution you want is to set the selection manually to the errored text.
http://strugglesofacoder.blogspot.com/2011/02/show-popup-under-text-in-rich-textbox.html
您可能想要弹出的是 子窗口。默认情况下,此控件在显示时会在当前控件上创建一个覆盖层,并带有一个小的可自定义弹出窗口。
出于您的目的,我建议通过直接从 ChildWindow 控件继承来创建新的自定义控件。有一个关于子窗口的使用/创建的小教程 在这里。为了让它出现在您的文本中,您需要确定拼写错误所在位置的某种坐标,然后将其传递到您的 ChildWindow 并适当设置边距。
What you're likely looking for to make the pop up is a ChildWindow. This control by default creates an overlay over your current control when shown, and a small customizable popup with it.
For your purposes, I'd recommend creating your new custom control by inheriting directly from the ChildWindow control. There's a small tutorial on the usage/creation of a child window here. To get it to appear at your text, you'll need to determine some sort of coordinates of where the spelling error is, then pass it into your ChildWindow and set the margins appropriately.