2017-06-22 10 views
2

仮想キーボードが開くと、私のロボットの顔が押し上げられるUWPアプリケーションがあります。仮想キーボードが開いたときに、スクロールビューアを所定の位置に保持し、テキストボックスを表示させておくことは可能ですか?UWP仮想キーボードがコンテンツをプッシュアップ

オープンイベントと非表示イベントを購読することができますが、uiエレメントの表示と非表示を切り替えることはできません。 https://docs.microsoft.com/en-us/windows/uwp/input-and-devices/respond-to-the-presence-of-the-touch-keyboard

<Page 
    x:Class="VirtualKeyboardFix.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:VirtualKeyboardFix" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
     <ScrollViewer > 
      <Image Source="image.png" /> 
     </ScrollViewer> 
     <TextBox HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="10" /> 
    </Grid> 
</Page> 

Image of robot with hidden face

+0

キーボードが表示させるための十分なスペースがない場合、通常コンテンツが押し上げられます。これはここのケースですか? –

+0

画像を追加するとその質問に答えることはできますか?ああ。私はあなたが意味することを得た。このイメージは、この場合の画面とほぼ同じサイズです。 – Haydn

+0

フォーカスを取得したときに、テキストボックスのオフセット(マイナス)を手動で設定することができます。 –

答えて

3

はい、それは答えジャスティンXLです。どうもありがとう。コメントではなく返信として投稿したい場合は、回答としてマークします。

誰もが同じ問題を抱えている場合に備えてください。

namespace VirtualKeyboardFix 
{ 
    /// <summary> 
    /// An empty page that can be used on its own or navigated to within a Frame. 
    /// </summary> 
    public sealed partial class MainPage : Page 
    { 
     public MainPage() 
     { 
      this.InitializeComponent(); 

      InputPane.GetForCurrentView().Showing += MainPage_Showing; 
      InputPane.GetForCurrentView().Hiding += MainPage_Hiding; 
     } 

     private void MainPage_Showing(InputPane sender, InputPaneVisibilityEventArgs args) 
     { 
      args.EnsuredFocusedElementInView = false; 
      InputTextBox.Margin = new Thickness(10, 10, 10, args.OccludedRect.Height + 10); 
     } 

     private void MainPage_Hiding(InputPane sender, InputPaneVisibilityEventArgs args) 
     { 
      args.EnsuredFocusedElementInView = false; 
      InputTextBox.Margin = new Thickness(10, 10, 10, 10); 
     } 
    } 
} 

Fixed Image

+3

これは答えとしてマークする必要があります。まあ値する。 ;) –

関連する問題