开发者

Silverlight C# - Set selection in textbox via code?

I'm working on a spellcheck function for my app, and want to have the word that's currently being looked at highlighted. I'm tracking the char count as I loop through the words in the textbox, so I know where to set the selection at.

I've tried txtArticle.Select(0, 10); just as a test, as well as setting the txtArticle.SelectionStart and txtArticle.SelectionLength properties, but the textbox doesn't show anything highlighted. What's the dealio?

Actual code I've tried:

txtArticle.SelectionStart = charCount;
txtArticle.SelectionLength = checkedWord.Length;

as well as

txtArticle.Select(charCount, checkedWord.Length);

I've positively no idea what I'm doing wrong, unless you can't set what's se开发者_运维百科lected in the TextBox via code, which I just can't imagine is the case. Is there perhaps some extra property that I need to set for the TextBox itself?

Thanks yet again!

-Sootah


Documentation on MSDN of TextBox.SelectionStart Property has an example that works. This states that programmatic text selection is actually supported in Silverlight.

Looks like something else is going wrong in your application. When do you call this code? Try calling it after everything is loaded, and rendered on screen. May be on a click of a button.

If above does not work, create a sample application/page and try to follow MSDN example. When you get it working, try to figure out why it doesn't work in your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜