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

I need to set focus on the text box. The problem is that the WebBrowser control is present on the page, SIP is displayed as if a text field had been selected, but the cursor does not appear in the text field, and the input does not fall into the text field.

If I comment on the WebBrowser control, then the behavior will be as expected - the cursor blinks in the TextBox when the page loads.

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 codebehind:

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

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

- ?

BTW, , HTC Mozart Trophy NoDo.

+5
5

Mango WP7, . , !

WP7 Mango !

0

1: , u

<StackPanel x:Name="ContentPanel" Margin="2,0,2,0">
  <TextBox x:Name="SearchTextBox" Height="90" VerticalAlignment="Top" 
           Loaded="SearchTextBox_Loaded"
           KeyDown="SearchTextBox_KeyDown"/>
</StackPanel>

step-2: Focus,

private void SearchTextBox_Loaded(object sender, RoutedEventArgs e)  
{  
    (sender as TextBox).Focus();  
}
+2

txt.Focus(). , ListBox. Control.Focus(), ( 3 GotFocus), , , .

+1

, . WebBrowser . TextBox LostFocus. - :

txt.LostFocus += new RoutedEventHandler(txt_LostFocus);

, WebBrowser :

void txt_LostFocus(object sender, RoutedEventArgs e)
{
    LayoutRoot.Children.Add(new WebBrowser());
}

, WebBrowser , .

0

- GotFocus. , txt.SelectionStart = txt.Text.Length; .

0

All Articles