2017-10-17 20 views
0

PageRendererの使用にはいくつか問題があります。XamarinフォームUWP PageRenderer

MainPage.xml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
       x:Class="abc.CustomView"> 
    <ContentPage.Content> 
      <StackLayout> 
       <Button Text="scann" Clicked="BtnScannClicked"></Button> 
      </StackLayout> 
    </ContentPage.Content> 

MainPage.cs

async void BtnScannClicked(object sender, EventArgs e) 
     { 
      await Navigation.PushAsync(new CustomView()); 
     } 

CustomView.Xaml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="abc.CustomView"> 
    <ContentPage.Content> 
    </ContentPage.Content> 
</ContentPage> 

CustomView.cs

[XamlCompilation(XamlCompilationOptions.Compile)] 
    public partial class CustomView : ContentPage 
    { 
     public CustomView() 
     { 
      InitializeComponent(); 
     } 
    } 
(私のCustomRendererです)

DemoPage.cs

[assembly: ExportRenderer(typeof(CustomView), typeof(DemoPage))] 
namespace abc.UWP 
{ 
    class DemoPage: PageRenderer 
    { 
     Page page; 
     Application app; 


     protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Page> e) 
     { 
      base.OnElementChanged(e); 

      if (e.OldElement != null || Element == null) 
      { 
       return; 
      } 
      try 
      { 
       app = Application.Current; 

       SetupUserInterface(); 
       this.Children.Add(page); 
      } 
      catch (Exception ex) 
      { 
       Debug.WriteLine(@"  ERROR: ", ex.Message); 
      } 
     } 


     void SetupUserInterface() 
     { 
      var stackPanel = new StackPanel(); 
      page = new Page(); 
      page.Content = stackPanel; 
     } 
    } 
} 

スロー 例外は常にあります:ビルド中Xamarin.Forms.Platform.UAP.dll エラーの 'System.InvalidOperationExceptionが' を。

しかし、これは実際にPageRendererの問題ではないと思います。これはClickEvent中に表示されます。

+0

ok、問題は、PushModalAsyncではなくNavigation.PushAnsyncの使用でした。これで、ナビゲーション部分が動作するようになりました(DemoPage.csのexportRendererアセンブリなし)。私のアプリケーションは、DemoPage.csへのナビゲーション後、常にクラッシュしています(終了コード-1を持っています)。実装は大丈夫かどうか? – flix

答えて

0

ビルド中にXamarin.Forms.Platform.UAP.dllエラーで「System.InvalidOperationException」がスローされることがあります。

MainPageNavigationPageに追加していないという問題があります。 PushAsyncメソッドは、Windowsではグローバルにサポートされていません。この問題を解決するには、次のコードをapp.xaml.csファイルに追加します。

public App() 
{ 
    InitializeComponent(); 
    var RootNav = new NavigationPage(new MainPage()); 
    MainPage = RootNav; 
} 

PushModalAsync - モーダルコンテキストにページを押してください。これにより、アプリケーション内に新しい独立したナビゲーションコンテキストが作成されます。作成されたモーダルは、ハードウェアの戻るボタンで閉じることができます。この機能を停止する方法はありません。

したがって、PushModalAsyncメソッドはNavigationPageに依存しないため、現在のシナリオでは機能します。

私のアプリケーションは、DemoPage.csへのナビゲーションの後、常にクラッシュしています(終了コード-1を持っています)。実装は大丈夫かどうか?

PageRendererにArrangeOverrideメソッドを実装していないことが判明しました。ページの内容は表示されません。

protected override Size ArrangeOverride(Size finalSize) 
{ 
    page.Arrange(new Windows.Foundation.Rect(0, 0, finalSize.Width, finalSize.Height)); 
    return finalSize;   
} 
関連する問題