In WP7 TextBox.Focus() does not work when WebBrowser control is present on page

I need to set focus on the textbox. The problem is when a WebBrowser control is present on the page, the SIP is displayed as if textbox is selected, but cursor is not visible in textbox and the input does not go to the textbox.

If I comment the WebBrowser control out, then the behavior is as expected - cursor is blinking in the TextBox when page is loaded.

Here is the XAML:

<phone:PhoneApplicationPage 
x:Class="WP7Sample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
Loaded="MainPageLoaded">

<StackPanel x:Name="LayoutRoot">
    <TextBox x:Name="txt"/>
    <phone:WebBrowser/>
</StackPanel>

</phone:PhoneApplicationPage>

And the codebehind:

void MainPageLoaded(object sender, RoutedEventArgs e)
{
    txt.Focus();
}

I have tried the different workarounds, but no luck. Namely I have tried to call SetFocus from the Load, NavigatedTo etc events. I have also tried to set focus to some other control and then back to the textbox, no luck either.

Could someone provide a workaround for this problem?

BTW, the problem is reproduced on the emulator, on HTC Mozart and Trophy devices all with NoDo update installed.

5
задан kza 10 May 2011 в 08:53
поделиться