我想在本地的Xamarin webview中加載Web應用程序(Readium)。作爲一個目標,我擁有UWP,Android和iOS。 我無法打開index.html頁面,根據https://developer.xamarin.com/guides/xamarin-forms/user-interface/webview/,我在每個項目中嵌入了網頁,但是我得到一個空白頁面。Xamarin Forms Webview本地
已經實現了依賴的服務,爲每一個應用程序,如(UWP)
assembly: Dependency(typeof(BaseUrl))]
namespace WorkingWithWebview.UWP
{
public class BaseUrl : IBaseUrl
{
public string Get()
{
return "ms-appx-web:///";
}
}
}
但是,創建一個新的UWP項目(不含Xamarin),它工作得很好,利用該方法NavigateToLocalStreamUri(URI,新StreamUriWinRTResolver( ))與
public IAsyncOperation<IInputStream> UriToStreamAsync(Uri uri)
{
if (uri == null)
{
throw new Exception();
}
string path = uri.AbsolutePath;
return GetContent(path).AsAsyncOperation();
}
private async Task<IInputStream> GetContent(string path)
{
try
{
Uri localUri = new Uri("ms-appx:///cloud-reader" + path);
StorageFile f = await StorageFile.GetFileFromApplicationUriAsync(localUri);
IRandomAccessStream stream = await f.OpenAsync(FileAccessMode.Read);
return stream;
}
catch (Exception)
{
throw new Exception("Invalid path");
}
}
以什麼方式在Xamarin Forms中完成相同的操作? 謝謝。