Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Bug: Can not programmatically focus controls in ScrollViewer
3 replies. Latest Post by Yi-Lun Luo - MSFT on May 7, 2008.
(0)
jseaver
Member
14 points
14 Posts
05-03-2008 5:24 PM |
I have wrapped a ScrollViewer around a 'form' that contains a number of textboxes. I am unable to programmatically set the focus to the textboxes using something like Textbox1.focus();
I need to be able to move focus from textbox to textbox as the user performs certain actions.
If I remove the ScrollViewer it works fine.
Although the focus method returns true, focus has not been set to a textbox. I assume it is being intercepted somehow by the ScrollViewer.
Yi-Lun L...
All-Star
25052 points
2,747 Posts
05-06-2008 3:22 AM |
Hello, can you post some code? I can't reproduce this issue. This is what I tried:
{
t2.Focus();
}
The second TextBox successfully got focused after clicking the Button.
05-06-2008 10:56 AM |
Try it with something other than a button. Add the following code below the button listed in your sample:
05-07-2008 12:17 AM |
Well, ScrollViewer handles MouseLeftButtonDown and changes focus internally:
private void OnMouseLeftButtonDown(MouseButtonEventArgs e) { if (!e.Handled && base.Focus()) { e.Handled = true; } }
So either set e.Handled = true in your own MouseLeftButtonDown event handler, or handle MouseLeftButtonUp instead.