2015-10-16 35 views
1

我開發了一個通用應用程序,它使用登錄表單,允​​許用戶連接或創建帳戶。在包含Windows Phone 8.1上的TextBox的ScrollViewer中進行自動滾動

這是一個簡單的表格,其中包含TextBoxPasswordBox。我的問題是,它不容易爲用戶各字段之間進行切換:和 enter image description here

=>例如,當用戶在第二字段中輸入,他必須停用鍵盤,在字段滾動選擇第三場。

通過comparaison的的Windows Store帳戶的創建形式,它是更加人性化: enter image description here

=>當用戶將焦點放到一個場,下一場也可見,就好像有與這些字段相對應的自動滾動。所以用戶不需要停用鍵盤進入下一個字段。所有的領域也可以很容易地輸入。

有沒有辦法允許重現這個? 我已經使用的代碼隱藏 「的KeyDown」 事件,即允許用戶在字段之間用開關 「輸入」:

private void RegisterTextBox_KeyDown(object sender, KeyRoutedEventArgs e) 
    { 
     TextBox currentTextBox = (TextBox)sender; 
     if (currentTextBox != null) 
     { 
      if (e.Key == Windows.System.VirtualKey.Enter) 
      { 
       FocusManager.TryMoveFocus(FocusNavigationDirection.Next); 
      } 
     } 
    } 

有了這個XAML:

<ScrollViewer x:Name="RegisterScrollViewer"> 
     <StackPanel> 
      <TextBlock x:Uid="loginRegisterTextblockMessage" 
         Style="{StaticResource TitleTextBlockStyle}" 
         Text="Remplissez vos informations d'inscription" /> 
      <TextBox x:Uid="loginRegisterTextboxOrganizationURL" 
        Header="Organization or URL" 
        IsSpellCheckEnabled="False" 
        IsHitTestVisible="True" 
        IsTextPredictionEnabled="False" 
        Text="{Binding OrganizationURL, Mode=TwoWay}" 
        TabIndex="10" 
        KeyDown="RegisterTextBox_KeyDown" 
        /> 
      <TextBox x:Uid="loginRegisterTextboxLastName" 
        Header="Name" 
        Text="{Binding LastName, Mode=TwoWay}" 
        TabIndex="20" 
        KeyDown="RegisterTextBox_KeyDown" 
        /> 
      <TextBox x:Uid="loginRegisterTextboxFirstName" 
        Header="First name" 
        Text="{Binding FirstName, Mode=TwoWay}" 
        TabIndex="30" 
        KeyDown="RegisterTextBox_KeyDown" 
        /> 
      <TextBox x:Uid="loginRegisterTextboxEmail" 
        Header="Email" 
        InputScope="EmailSmtpAddress" 
        Text="{Binding Email, Mode=TwoWay}" 
        TabIndex="40" 
        KeyDown="RegisterTextBox_KeyDown" 
        /> 
      <PasswordBox x:Uid="loginRegisterPasswordboxPassword" 
         Header="Password" 
         Password="{Binding Password, Mode=TwoWay}" 
         TabIndex="50" 
         KeyDown="RegisterPasswordBox_KeyDown" 
         /> 
      <PasswordBox x:Uid="loginRegisterPasswordboxConfirmPassword" 
         Header="Confirm password" 
         Password="{Binding PasswordConfirmation, Mode=TwoWay}" 
         TabIndex="60" 
         KeyDown="RegisterPasswordBox_KeyDown" 
         /> 
      <CheckBox x:Uid="loginRegisterCheckboxTermsOfUse" 
         IsChecked="{Binding TermsOfUse, Mode=TwoWay}" 
         TabIndex="70 "> 
       <TextBlock Style="{StaticResource BaseTextBlockStyle}"> 
        <Run x:Uid="loginRegisterTextblockTermsOfUse1" 
         Text="I accept " /> 
        <Underline> 
         <Hyperlink x:Uid="loginRegisterHyperlinkTermsOfUse" 
            NavigateUri="http://termsofuse.html" > 
          <Run x:Uid="loginRegisterTextblockTermsOfUse2" 
           Text="terms of use" /> 
         </Hyperlink> 
        </Underline> 
       </TextBlock> 
      </CheckBox> 
      <Button x:Uid="loginRegisterButtonRegister" 
        Content="Subscribe" 
        Command="{Binding RegisterCommand}" 
        TabIndex="80" 
        /> 
     </StackPanel> 
    </ScrollViewer> 

但是這並不能解決沒有使用「回車」鍵而發生的問題。

回答

0

當TextBox聚焦(焦點事件)時,可以嘗試使用ScrollViewer.ChangeView以編程方式將窗體滾動到所需的位置。通過使用InputPaneShowing和InputPaneHiding事件獲取鍵盤高度並作出相應的反應,可以改進此行爲。

相關問題