Windows手机键盘显示

时间:2014-10-31 01:19:23

标签: windows-phone

有没有办法配置Windows手机键盘的显示方式? 我有一个listview,每个项目都有一个TextBox。

当我点击TextBox时,键盘会显示,弹出的文本框(导致键盘)将固定在键盘顶部。

例如,如果我从列表末尾点击最后一个文本框,当键盘弹出时,第二个最后一个TextBox将锚定在键盘顶部,键盘将覆盖最后一个文本框。

有没有改变这种行为?

1 个答案:

答案 0 :(得分:0)

**XAML**

  <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="24,0,0,0">
            <TextBlock x:Name="PageTitle" Text="sign in" Margin="0,0,0,0" Height="125" Style="{StaticResource PhoneTextTitle1Style}" Tap="PageTitle_Tap"/>
        </StackPanel>

        <ScrollViewer Grid.Row="1" x:Name="Scroller" VerticalAlignment="Top">
            <Grid x:Name="ContentPanel" Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <TextBlock Grid.Row="0" Name="EnterUserIdTitle" Margin="24,0,14,6" FontSize="26" Text="Username"/>
                <TextBox Grid.Row="1" Name="EnterUserIdInput" Margin="12,0,24,6" Text=""  GotFocus="EnterUserIdInput_GotFocus" LostFocus="UserIdLostFocus" />

                <TextBlock Grid.Row="2" Name="EnterPwdTitle" Margin="24,0,14,6" FontSize="26" Text="Password"/>
                <PasswordBox Grid.Row="3" Name="EnterPwdInput" Margin="12,0,24,6" GotFocus="EnterPwdInput_GotFocus" LostFocus="EnterPwdInput_LostFocus"/>

                <TextBlock Grid.Row="4" Name="ServerUrlTitle" Margin="24,10,24,6" FontSize="26" Text="namespace"/>
                <TextBox Grid.Row="5" Name="ServerUrlInput" Margin="12,0,24,6" Text="" TextWrapping="Wrap" GotFocus="ServerUrlInput_GotFocus" LostFocus="ServerUrlInput_LostFocus"/>
                <Grid Grid.Row="6" Name="DebugEndPointGrid">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Row="0" Name="DebugEndpointTitle" Margin="24,10,24,6" FontSize="26" Text="End Point"/>
                    <TextBox Grid.Row="1" Name="DebugEndpoint" Height="72" Margin="12,0,24,6" GotFocus="DebugEndpoint_GotFocus" LostFocus="DebugEndpoint_LostFocus" />
                </Grid>
                <CheckBox Grid.Row="7" Name="RemeberCheckbox" Margin="12,0,24,6" Content="Remember Me" IsChecked="True"/>

            </Grid>
        </ScrollViewer>
    </Grid>


----------
**C#**

     public partial class MainPage : PhoneApplicationPage
    {
        public const string SettingsPageUri = @"/SettingsPage.xaml";

        private double DefaultScrollerHeight;
        private int SIPVisibleScrollerHeight = 250;
        private int UserIDOffset = 0;
        private int PasswordOffset = 110;
        private int ServiceUrlOffset = 250;
        private int DebugOffset = 300;
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(SettingsPage_Loaded);
        }

        private void SettingsPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Code to avoid screen from pushing upward on launch of SIP and provides options to resize the scroller and remove elastic effect from forms by enabling scrollers when SIP is activated.
            // Header also does not push up when textbox gets focus.
            //(App.Current as App).RootFrame.RenderTransform = new CompositeTransform();

            DefaultScrollerHeight = this.Scroller.Height;

            EnterUserIdInput.Tag = false;
            EnterPwdInput.Tag = false;
            ServerUrlInput.Tag = false;
            DebugEndpoint.Tag = false;
        }

        private void EnterUserIdInput_GotFocus(object sender, RoutedEventArgs e)
        {
            EnterUserIdInput.Tag = true;
            if (this.Scroller.Height != SIPVisibleScrollerHeight)
            {
                this.Scroller.Height = SIPVisibleScrollerHeight;
                this.Scroller.UpdateLayout();
                this.Scroller.ScrollToVerticalOffset(UserIDOffset);
            }
        }

        private void UserIdLostFocus(object sender, RoutedEventArgs e)
        {
            EnterUserIdInput.Tag = false;
        }

        private void EnterPwdInput_GotFocus(object sender, RoutedEventArgs e)
        {
            EnterPwdInput.Tag = true;

            if (this.Scroller.Height != SIPVisibleScrollerHeight)
            {
                this.Scroller.Height = SIPVisibleScrollerHeight;
                this.Scroller.UpdateLayout();
                this.Scroller.ScrollToVerticalOffset(PasswordOffset);
            }
        }

        private void EnterPwdInput_LostFocus(object sender, RoutedEventArgs e)
        {
            EnterPwdInput.Tag = false;
        }

        private void ServerUrlInput_GotFocus(object sender, RoutedEventArgs e)
        {
            ServerUrlInput.Tag = true;

            if (this.Scroller.Height != SIPVisibleScrollerHeight)
            {
                this.Scroller.Height = SIPVisibleScrollerHeight;
                this.Scroller.UpdateLayout();
                this.Scroller.ScrollToVerticalOffset(ServiceUrlOffset);
            }
        }

        private void ServerUrlInput_LostFocus(object sender, RoutedEventArgs e)
        {
            ServerUrlInput.Tag = false;
        }

        private void DebugEndpoint_GotFocus(object sender, RoutedEventArgs e)
        {
            DebugEndpoint.Tag = true;

            if (this.Scroller.Height != SIPVisibleScrollerHeight)
            {
                this.Scroller.Height = SIPVisibleScrollerHeight;
                this.Scroller.UpdateLayout();
                this.Scroller.ScrollToVerticalOffset(DebugOffset);
            }
        }

        private void DebugEndpoint_LostFocus(object sender, RoutedEventArgs e)
        {
            DebugEndpoint.Tag = false;
        }

        private void SettingsPage_GotFocus(object sender, RoutedEventArgs e)
        {
            if (!((bool)EnterUserIdInput.Tag) && !((bool)EnterPwdInput.Tag) && !((bool)ServerUrlInput.Tag) && !((bool)DebugEndpoint.Tag))
            {
                this.Scroller.Height = DefaultScrollerHeight;
                this.Scroller.UpdateLayout();
            }
        }
        private void PageTitle_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            this.Scroller.Height = DefaultScrollerHeight;
            this.Scroller.UpdateLayout();
        }
    }