2015-10-13 71 views
0

我創建了一個簡單的現代UI應用程序,該應用程序在加載應用程序時顯示WebView上本地主機站點的內容。當我調試它時,該應用完美運行。我已經用Visual Studio Remote Tools將它部署到另一臺機器上,並且按預期工作。WebView應用程序顯示空白頁面

但是,當我在Windows商店中發佈它,然後從那裏安裝應用程序時,頁面爲空白。商店中的應用程序名稱爲Locked Browser Lite。

我將不勝感激任何建議。

下面的代碼:

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Runtime.InteropServices.WindowsRuntime; 
using Windows.Foundation; 
using Windows.Foundation.Collections; 
using Windows.UI.Xaml; 
using Windows.UI.Xaml.Controls; 
using Windows.UI.Xaml.Controls.Primitives; 
using Windows.UI.Xaml.Data; 
using Windows.UI.Xaml.Input; 
using Windows.UI.Xaml.Media; 
using Windows.UI.Xaml.Navigation; 

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 

namespace App3 
{ 
    /// <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(); 
      this.Loaded += PageLoaded; 
      this.Unloaded += PageUnloaded; 

      wvMain.HorizontalAlignment = HorizontalAlignment.Stretch; 
      wvMain.VerticalAlignment = VerticalAlignment.Stretch; 

      //wvMain.Source = new Uri("http://localhost"); 
     } 

     private void PageUnloaded(object sender, RoutedEventArgs e) 
     { 
      Window.Current.SizeChanged -= Window_SizeChanged; 
     } 

     private void PageLoaded(object sender, RoutedEventArgs e) 
     { 
      Window.Current.SizeChanged += Window_SizeChanged; 

      Uri targeturi = new Uri("http://localhost"); 
      wvMain.Navigate(targeturi); 
      //wvMain.Refresh(); 
     } 

     private void Window_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e) 
     { 
      wvMain.HorizontalAlignment = HorizontalAlignment.Stretch; 
      wvMain.VerticalAlignment = VerticalAlignment.Stretch; 
     } 

     private void btnReload_Click(object sender, RoutedEventArgs e) 
     { 
      PageLoaded(sender, e); 
     } 
    } 
} 

回答

0

什麼是 'localhost' 的?

我試過你的應用程序,是的,它是空白的應用程序..因爲你請求的網址,你要求你的應用程序導航到本地主機,而我的機器上沒有本地服務器!

如果你有一些自定義的HTML頁面展示給你的用戶,儘量使其脫機可用作爲一個HTML文件,然後使用webview.NavigateToString(從文件中讀取HTML)..

+0

我有一個網頁服務器在本地主機上提供Web應用程序。如果我使用Internet Explorer(城域和桌面),它工作正常。但該應用程序(通過Windows商店安裝)顯示一個空白頁面。如果我通過Visual Studios Remote Tools部署應用程序,它可以正常工作。我猜測Windows應用商店對應用增加了某種限制? –

+0

是的,主要是因爲商店 –

+0

應用程序被沙箱化,無法連接到本地主機。但是,有這個方便的工具:https://loopback.codeplex.com/ – AyCe