Windows Phone Get Keyboard Height

I am working on a Windows Phone 8 application when I need to do some special processing when the keyboard is displayed. Is there a way that I can get the height of the keyboard in the current orientation.

thanks

+4
source share
4 answers

I managed to do this in Windows Phone 8.1, but there was a bit of space in the text box with the save button and the top headers above.

<Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <!--ScrollViewer Background="#302010" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"--> <TextBox x:Name="text" ManipulationDelta="textList_ManipulationDelta" ManipulationMode="Scale" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="Wrap" AcceptsReturn="True" > </TextBox> <Rectangle x:Name="rectRed" Fill="Red" Grid.Row="2" Height="10" /> <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="1" Fill="#30000000" /> <StackPanel x:Name="stackAppBar" Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center"> <AppBarButton Icon="Save" Label="Save" IsCompact="true" x:Name="buttonSave" Click="buttonSave_Click"/> <!--AppBarButton Icon="Delete" Label="Delete" IsCompact="true"/--> </StackPanel> <!--Rectangle x:Name="rectKeyboard" Fill="Red" Grid.Row="2" Height="200" /--> </Grid> async void UCSetup_Loaded(object sender, RoutedEventArgs e) { // put text in box string s = await IO.ReadSetupFile(); text.Text = s; InputPane.GetForCurrentView().Showing += UCSetup_Showing; InputPane.GetForCurrentView().Hiding += UCSetup_Hiding; } void UCSetup_Hiding(InputPane sender, InputPaneVisibilityEventArgs args) { var size = args.OccludedRect; rectRed.Height = size.Height; } void UCSetup_Showing(InputPane sender, InputPaneVisibilityEventArgs args) { var size = args.OccludedRect; rectRed.Height = size.Height; } 
+2
source

There is no good way to do this in XAML, although you can just run your code whenever the TextBox.GotFocus event TextBox.GotFocus . The easiest way to do this is to simply subclass the TextBox and fire your own custom event when the parent GotFocus event is GotFocus .

If you are writing your own native application, you can find this by checking the occlusal area of โ€‹โ€‹your window. An example of this can be found at the end: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj247546(v=vs.105).aspx

+1
source

It is not possible to get the actual height of the keyboard, but if the keyboard caused the screen to scroll because the text field was in the lower half, you can find out how far it scrolled by looking at the offset of the root frame.

See How to determine keyboard offset for more details / code.

+1
source

For Windows Phone 8.1 RT, just add the following code to your xaml.cs.

 // This part in the constructor of the page InputPane inputPane = InputPane.GetForCurrentView(); inputPane.Showing += InputPane_Showing; inputPane.Hiding += InputPane_Hiding; private void InputPane_Hiding(InputPane sender, InputPaneVisibilityEventArgs args) { // Do what you want. } private void InputPane_Showing(InputPane sender, InputPaneVisibilityEventArgs args) { Debug.WriteLine("Keyboard Height: "sender.OccludedRect.Height); } 
0
source

Source: https://habr.com/ru/post/1488391/


All Articles