2017-04-17 5 views
0

私はXamarinフォームの最新バージョンを使用しています。私はコンテンツページを持つカルーセルページを持っています。コンテンツページには、スクロールビューがあり、いくつかのラベルと入力入力を含むスタックレイアウトがあります。入力をタッチしてテキストを入力すると、キーボードが入力ボックスを覆い、入力したものが表示されません。私のXamarinフォームPCLカルーセルページのキーボードは、自分の入力フィールドをカバーしています

私はベーシックアプリで、8個のラベルと8個のエントリを持つコンテンツページ(カルーセルなし)を使用し、キーボードが表示されているときにエントリボックスが上にスクロールして表示されることをテストしましたに。

しかし、上記のコンテンツページを子供として追加するカルーセルページを使用すると、キーボードは自分の入力フィールドをカバーします。

ので、下記の作品:

public App() 
    { 
     InitializeComponent(); 

     MainPage = new MainPage1(); 
    } 


namespace App2 
{ 

    [XamlCompilation(XamlCompilationOptions.Compile)] 
    public partial class MainPage1 : ContentPage 
    { 
     public MainPage1() 
     { 
      InitializeComponent(); 

      var vScrollView = new ScrollView 
      { 
       HorizontalOptions = LayoutOptions.Center, 
       VerticalOptions = LayoutOptions.FillAndExpand, 
       Margin = new Thickness(0, 5, 15, 25), 

      }; 
      var vStackLayout = new StackLayout 
      { 
       Orientation = StackOrientation.Vertical, 
       Spacing = 10, 
       HorizontalOptions = LayoutOptions.Start, 
       VerticalOptions = LayoutOptions.Start, 
       Margin = new Thickness(15, 0, 15, 25), 
       WidthRequest = 700 
      }; 

      //Create the form label for the item 
      var lblItemLabel = new Label 
      { 
       Text = "Label 1", 
       FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), 
       Margin = new Thickness(10, 0, 0, 0), 
      }; 
      vStackLayout.Children.Add(lblItemLabel); 

      var entry = new Entry 
      { 
       //HorizontalOptions = LayoutOptions.Fill, 
       MinimumWidthRequest = 300, 
       Margin = new Thickness(20, 0, 15, 15), 
      }; 
      vStackLayout.Children.Add(entry); 

      var lblItemLabel2 = new Label 
      { 
       Text = "Label 2", 
       FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), 
       Margin = new Thickness(10, 0, 0, 0), 
      }; 
      vStackLayout.Children.Add(lblItemLabel2); 

      var entry2 = new Entry 
      { 
       //HorizontalOptions = LayoutOptions.Fill, 
       MinimumWidthRequest = 300, 
       Margin = new Thickness(20, 0, 15, 15), 
      }; 
      vStackLayout.Children.Add(entry2); 

      var lblItemLabel3 = new Label 
      { 
       Text = "Label 3", 
       FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), 
       Margin = new Thickness(10, 0, 0, 0), 
      }; 
      vStackLayout.Children.Add(lblItemLabel3); 

      var entry3 = new Entry 
      { 
       //HorizontalOptions = LayoutOptions.Fill, 
       MinimumWidthRequest = 300, 
       Margin = new Thickness(20, 0, 15, 15), 
      }; 
      vStackLayout.Children.Add(entry3); 

      var lblItemLabel4 = new Label 
      { 
       Text = "Label 4", 
       FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), 
       Margin = new Thickness(10, 0, 0, 0), 
      }; 
      vStackLayout.Children.Add(lblItemLabel4); 

      var entry4 = new Entry 
      { 
       //HorizontalOptions = LayoutOptions.Fill, 
       MinimumWidthRequest = 300, 
       Margin = new Thickness(20, 0, 15, 15), 
      }; 
      vStackLayout.Children.Add(entry4); 

      var lblItemLabel5 = new Label 
      { 
       Text = "Label 5", 
       FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), 
       Margin = new Thickness(10, 0, 0, 0), 
      }; 
      vStackLayout.Children.Add(lblItemLabel5); 

      var entry5 = new Entry 
      { 
       //HorizontalOptions = LayoutOptions.Fill, 
       MinimumWidthRequest = 300, 
       Margin = new Thickness(20, 0, 15, 15), 
      }; 
      vStackLayout.Children.Add(entry5); 

      var lblItemLabel6 = new Label 
      { 
       Text = "Label 6", 
       FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), 
       Margin = new Thickness(10, 0, 0, 0), 
      }; 
      vStackLayout.Children.Add(lblItemLabel6); 

      var entry6 = new Entry 
      { 
       //HorizontalOptions = LayoutOptions.Fill, 
       MinimumWidthRequest = 300, 
       Margin = new Thickness(20, 0, 15, 15), 
      }; 
      vStackLayout.Children.Add(entry6); 

      var lblItemLabel7 = new Label 
      { 
       Text = "Label 7", 
       FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), 
       Margin = new Thickness(10, 0, 0, 0), 
      }; 
      vStackLayout.Children.Add(lblItemLabel7); 

      var entry7 = new Entry 
      { 
       //HorizontalOptions = LayoutOptions.Fill, 
       MinimumWidthRequest = 300, 
       Margin = new Thickness(20, 0, 15, 15), 
      }; 
      vStackLayout.Children.Add(entry7); 

      var lblItemLabel8 = new Label 
      { 
       Text = "Label 8", 
       FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), 
       Margin = new Thickness(10, 0, 0, 0), 
      }; 
      vStackLayout.Children.Add(lblItemLabel8); 

      var entry8 = new Entry 
      { 
       //HorizontalOptions = LayoutOptions.Fill, 
       MinimumWidthRequest = 300, 
       Margin = new Thickness(20, 0, 15, 15), 
      }; 
      vStackLayout.Children.Add(entry8); 


      vScrollView.Content = vStackLayout; 
      Content = vScrollView; 
     } 
    } 

} 

をしかし、私はCarouselPageを作成し、子としての上記コンテンツページを追加するとき、キーボードはもはやビューを押し上げるません。代わりに、Entryフィールドをカバーします。

以下、動作しません:

public App() 
{ 
    InitializeComponent(); 

    MainPage = new CarouselPage1(); 
} 

namespace App2 
{ 

    [XamlCompilation(XamlCompilationOptions.Compile)] 
    public partial class CarouselPage1 : CarouselPage 
    { 
     public CarouselPage1() 
     { 
      InitializeComponent(); 

      var page = new MainPage1(); //Same exact MainPage1 as in first code block above. 
      this.Children.Add(page); 
     } 
    } 
} 

がどのように私はキーボードがCarouselPageを使用しているとき、私のエントリフィールドをカバーしていないことで正常に動作するのですか?

+0

誰でも?キーボードが表示されたときにページの変更を認識することはできません。 Page.Heightの変更メソッドまたはPage.LayoutChangeメソッドを使用しようとしましたが、キーボードが表示されたときに変更が認識されませんでした。どのように私は回避策をコード化することができます誰もが任意のアイデアを持っていますか?私はWindowsとiOSの両方を打つ必要があります。 – Stacy

答えて

0

この問題に対する彼の支援と解決策について、Kym Phillpotts @ Microsoft(Xamarin University)に感謝したいと思います。私のXamarin Universityの定期購読のおかげで、私はKymと1:1のクラス時間を使ってこの問題をレビューすることができました。最終的に私は以下のコードを修正プログラムとして提供しました。

修正プログラムは、UWPとWinPhone 8.1(iOSにはこのバグはありません)の両方で動作します。 KymはキーボードをキャプチャするためにXamarin Effectsを使用しました&イベントを非表示にし、スクロールビュー要素にエフェクトを登録しました。私のPCLでは

は、私はクラスを作成し、キムから以下のコードを配置:

using Xamarin.Forms; 

namespace App2 
{ 
    public class KeyboardSpacingEffect : RoutingEffect 
    { 
     public KeyboardSpacingEffect() : base("Xamarin.KeyboardSpacingEffect") 
     { 
     } 
    } 
} 

はその後UWPとWinPhoneプラットフォーム固有のプロジェクトでは、私はクラスを作成し、キムから、このコードを配置:

using App2.WinPhone; //Make sure this using statement correctly points to the platform specific project and not the PCL project or you will get an error. 
using System.Diagnostics; 
using Windows.UI.ViewManagement; 
using Xamarin.Forms; 
using Xamarin.Forms.Platform.WinRT; 

[assembly: ResolutionGroupName("Xamarin")] 
[assembly: ExportEffect(typeof(KeyboardSpacingEffect), "KeyboardSpacingEffect")] 
namespace App2.WinPhone 
{ 
    public class KeyboardSpacingEffect : PlatformEffect 
    { 
     protected override void OnAttached() 
     { 
      InputPane.GetForCurrentView().Showing += Keyboard_OnShow; 
      InputPane.GetForCurrentView().Hiding += Keyboard_OnHide; 

     } 

     private void Keyboard_OnHide(InputPane sender, InputPaneVisibilityEventArgs args) 
     { 
      // debug stuff 
      Debug.WriteLine("Keyboard hide"); 
      var x = Element; 
      var y = Control; 
      var z = Container; 
      Debug.WriteLine($"{x} - {y} - {z}"); 

      // get the scrollview element and remove the margin 
      ScrollView scrollView = Element as ScrollView; 
      scrollView.Margin = new Thickness(0, 0, 0, 0); 
     } 

     private void Keyboard_OnShow(InputPane sender, InputPaneVisibilityEventArgs args) 
     { 
      // debug stuff 
      var x = Element; 
      var y = Control; 
      var z = Container; 
      Debug.WriteLine($"{x} - {y} - {z}"); 

      // get the scrollview element and add some margin to the bottom = size of keyboard 
      ScrollView scrollView = Element as ScrollView; 
      scrollView.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height + 20); 
     } 

     protected override void OnDetached() 
     { 
      InputPane.GetForCurrentView().Showing += Keyboard_OnShow; 
      InputPane.GetForCurrentView().Hiding += Keyboard_OnHide; 
     } 
    } 
} 
関連する問題