I have a WP8 app with one page that has a textbox at the top, a couple other controls, three more textboxes, and two toggleswitches at the bottom. I'm using three Telerik RadToggleSwitches on the page, and one Telerik RadListPicker (3 items in the list).
In the code-behind, when any textbox gets focus, I create an ApplicationBar with two buttons. One of those buttons is Next, which moves the focus to the next textbox. When a textbox loses focus, I hide the applicationbar.
Now, the problem. Sometimes, seemingly completely at random, the page does not transform upward to make the textboxes visible from behind the SIP. InputScope, BTW, is Number. I can tap any of the textboxes, and sometimes it transforms upward as the SIP becomes visible, and sometimes it does not. Even just tapping textboxes back and forth, I can occasionally get it to not work.
Here's the pertinent code-behind.
void onSettingsLoaded(object sender, RoutedEventArgs e)
{
ApplicationBar = new ApplicationBar();
ApplicationBar.IsVisible = false;
}
private void onTextGotFocus(object sender, System.Windows.RoutedEventArgs e)
{
CreateTxtAppBar();
tb = sender as TextBox;
tb.SelectAll();
}
private void CreateTxtAppBar()
{
ApplicationBar.Buttons.Clear();
ApplicationBar.MenuItems.Clear();
ApplicationBar.IsVisible = true;
ApplicationBarIconButton btnNext = new ApplicationBarIconButton(new Uri("/Toolkit.Content/next.png", UriKind.Relative));
ApplicationBarIconButton btnOK = new ApplicationBarIconButton(new Uri("/Toolkit.Content/appbar.check.png", UriKind.Relative));
btnOK.Text = LStrings.OK;
btnNext.Text = LStrings.Next;
ApplicationBar.Buttons.Add(btnNext);
ApplicationBar.Buttons.Add(btnOK);
btnNext.Click += btnNext_Click;
btnOK.Click += onBtnOKClick;
}
void btnNext_Click(object sender, EventArgs e)
{
switch(tb.Name)
{
case "tb1":
this.Focus();
tb2.Focus();
break;
case "tb2":
tb3.Focus();
break;
case "tb3":
tb4.Focus();
break;
default:
tb1.Focus();
break;
}
}
private void onTextLostFocus(object sender, System.Windows.RoutedEventArgs e)
{
ApplicationBar.IsVisible = false;
ApplicationBar.Buttons.Clear();
ApplicationBar.MenuItems.Clear();
}
As you can see, I tried to get it to work by sticking a this.Focus() in places where I would need a change of focus, but that doesn't do it. There are times when I tap a textbox and there is no transform, and the keyboard hides the textbox that just received the focus - no other controls involved in the action.
Does anyone have any idea why this is happening? I haven't seen this behavior in WP7, so either I was lucky, or (more likely, since I can't seem to find any other posts with this exact problem) there is a new problem with WP8. Or it could be Telerik, as this is the first time I'm using them, but I'm not bullish on that one, since I can tap textboxes without coming from any of the Telerik controls and reproduce the problem.
Just in case it matters, here's markup from one of the textboxes. They're all essentially the same:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="2*" />
<ColumnDefinition
Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Text="{Binding Strings.Age,
Source={StaticResource LocalStrings}}"
Style="{Binding Source={StaticResource TBStyle}}" />
<TextBox
Name="tb2"
Grid.Column="1"
Style="{StaticResource TxtStyle}"
GotFocus="onTextGotFocus"
LostFocus="onTextLostFocus"
Text="{Binding Age,
Source={StaticResource Settings},
Mode=TwoWay}" />
</Grid>
This is all within a stackpanel, and the stackpanel is within a scrollviewer.
Thanks for your time - any help is appreciated.