2016-09-29 5 views
0

私はxamarin.formsポータブルプロジェクトの初心者です。私はxamainr.formsポータブルプロジェクトに取り組んでいます。ポータブルプロジェクトに.xamlページがあり、次のコード行を使用してApp.csからこの.xamlページに移動します。ここでCustomWebViewPageで MyCustomPage.xamlはxamarin.FormsポータブルのwebViewをロードしていません

var ep = new CustomWebViewPage(dbPath); 
var MainEv = new NavigationPage(ep); 

iは、WebViewのをロードしないURLをロードする方法を、次のではなく、行のエミュレータ上で実行が成功した後のWebViewを使用しています。私はなぜそれが起こっているのか分からない。 次のようにCustomWebViewPageのコードを貼り付けています。

CustomWebViewPage.xaml.cs

using XamarinDbokReader.SQLite_AppSample; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Xamarin.Forms; 
using System.IO; 

namespace MyDummyProject 
{ 
    public partial class CustomWebViewPage : ContentPage 
    { 
     public string dbPath = ""; 
     public CustomWebViewPage(string folderPath) 
     { 
      this.dbPath = folderPath; 
      HttpHelperClass helperClass = new HttpHelperClass(); 
      InitializeComponent(); 
      var webView = new WebView(); 
      UrlWebViewSource urlWebViewSource = new UrlWebViewSource() 
      { 
       Url = UrlsList.FindUrl("ProEportalLoginPage") + UrlsList.ApiKeys(AppMode.ProductionMode.ToString()) 
      }; 
       webView.Source = urlWebViewSource; 
       webView.Navigated += (s, e) => 
       { 
        if (e.Url.StartsWith("http://userInfo/?")) 
        { 
         string token = ""; 
         try 
         { 
          string value_string = Uri.UnescapeDataString(e.Url.ToString()); 
          token = value_string.Split('=')[1]; 
          if (!string.IsNullOrEmpty(token)) 
          { 
           string path = Path.Combine(dbPath.ToString(), "dBookStore.db3"); 
           helperClass.SaveUserInformation(token, path); 
          } 
         } 
         catch (Exception ss) 
         { 
         } 
        } 
      }; 
      wvEportalPage = webView; 
     } 
     public CustomWebViewPage() 
     { 

     } 
    } 
} 

CustomWebViewPage.xaml

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="XamarinDbokReader.EportalPage"> 
    <Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" /> 
    <WebView x:Name="wvEportalPage"></WebView> 
</ContentPage> 

App.cs

public App(bool isSqliteDbExist, string sPath) 
    { 
     isDbExist = isSqliteDbExist; 
     dbPath = sPath; 
     if (isDbExist) 
     { 
      if (isLoggedIn) 
      { 
       NavigationPage navPage = new NavigationPage(new BooksView()); 
       App.Current.MainPage = navPage; 
      } 
      else 
      { 
       var tdlx = new CustomWebViewPage(dbPath); 
       var MainNave = new NavigationPage(tdlx); 
      } 
     } 
     else 
     { 
      //When cursor is coming from MainActivity then following line executes. And then OnStart() method executes. 
      ssd.CreateTablesInDb(); 
      isDbExist = true; 
     } 
    } 

protected override void OnStart() 
    { 
     if (isDbExist) 
     { 
      if (isLoggedIn) 
      { 
       NavigationPage navPage = new NavigationPage(new BooksView()); 
       App.Current.MainPage = navPage; 
      } 
      else 
      { 
       var ep = new CustomWebViewPage(dbPath); 
       var MainEv = new NavigationPage(ep); 

      } 
     } 
    } 

MainActivity

protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 
     global::Xamarin.Forms.Forms.Init(this, bundle); 
     var documents = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); 
     var bookCoverFolder = Path.Combine(documents, "BooksCover"); 
     var booksCollection = Path.Combine(documents, "Books"); 
     var bookResource = Path.Combine(documents, "Resource"); 
     if(!Directory.Exists(bookCoverFolder)) 
      Directory.CreateDirectory(bookCoverFolder); 
     if (!Directory.Exists(booksCollection)) 
      Directory.CreateDirectory(booksCollection); 
     if(!Directory.Exists(bookResource)) 
      Directory.CreateDirectory(bookResource); 
     SQLite_Android androidDb = new SQLite_Android(); 
     if (androidDb.IsExist()) 
     { 
      LoadApplication(new App(true, androidDb.dbStorePath)); 
     } 
     else 
     { 
      LoadApplication(new App(false, androidDb.dbStorePath)); 

     } 
    } 
+0

このコードはコンパイルされません。あなたのクラス名は 'CustomWebViewPage'であり、コンストラクタは' EportalPage'です –

+0

はいステファン、あなたは正しいです、私は正しく名前を変更しました。 –

答えて

0

ありがとうございます。私は間違いを見つけました。私はApp.csで非常に小さな間違いを犯しました。ナビゲーションページを設定した後、NavigationPageをMainPageに設定していません。それは以下のようにする必要があります。

var tdlx = new CustomWebViewPage(dbPath); 
var MainNave = new NavigationPage(tdlx); 
MainPage = MainNave; 

完全に機能しました。私はMainPageについて知っていましたが、私は他の地域のために書いていませんが、最終的には働いています。

1

WebViewは、おそらくどのWidthHeightを取得されていません。

VerticalOptionsHorizontalOptionsのプロパティをFillAndExpandに設定してみてください。このようなので、

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="XamarinDbokReader.EportalPage"> 
    <Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" /> 
    <WebView x:Name="wvEportalPage" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"></WebView> 
</ContentPage> 

ことがGridでラップしようと動作していないようならば。

+0

ok、私はそれを試して、分にあなたを更新します。 –

+0

グリッドを適用すると、ページがCustomWebViewPageページにナビゲートされているが、黒い画面が表示されていることがわかります。私は解雇したURLページを見つけることができませんでした。 –

+0

カスタムURLなどをしようとしていますか? google.comのような簡単なもので試してみてください。それは何かを示していますか? –

0

Xamarin WebViewに幅と高さを定義する必要があります。

関連する問題