2013-08-28 2 views
0

내 응용 프로그램에 여러 html 페이지가 있습니다. 그 html 파일을 f1.html, f2.html, f3.html, \ ... f454.html으로 명명했습니다. 그래서, 나는이 파일들을 사용자 선호에 의해 표시하고 싶다. 그래서 CustomMessageBox에있는 텍스트 상자와 버튼을 NuGet과 webview.xaml이라는 이름의 xaml 페이지를 사용하여 만들었습니다. 사용자가 텍스트 상자에 3을 입력하면 f3.html이 webview.xaml에서 열려 있어야합니다.wp8 : webbrowser에서 버튼을 클릭하여 htm 페이지 열기?

코딩 방법을 모르겠습니다. 최선의 답변은 진지하게 높이 평가 될 것입니다.

C# 코드 지금까지 [업데이트]되었습니다. webview.xaml에서

TextBox getFileNo = new TextBox(); 
getFileNo.Height = 72; 
getFileNo.Width = 150; 
getFileNo.MaxLength = 3; 
TextBox getHashNo = new TextBox(); 
getHashNo.Height = 72; 
getHashNo.Width = 150; 
getHashNo.MaxLength = 3; 

string showFile; 
showFile = getFileNo.Text; 
string hashId; 
hashId = getHashNo.text; 
NavigationService.Navigate(new Uri("/webview.xaml?Page=" + site, UriKind.Relative)); 

:

 protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     base.OnNavigatedTo(e); 
     if (NavigationContext.QueryString.ContainsKey("Page")) 
     { 
      var page = NavigationContext.QueryString["Page"]; 
      browser.Navigate(new Uri("/f" + page + ".html#" + hashId, UriKind.Relative)); 
     } 
    } 

답변

0
당신이 원하는 HMTL 파일과 쿼리 문자열 통과 webview.xaml 페이지로 이동할 수 있습니다

: 당신의 웹뷰에서

NavigationService.Navigate(new Uri(String.Format("/webview.xaml?Page={0}&id={1}", showFile, hashId), UriKind.Relative)); 

.xaml 페이지에서 OnNavigatedTo 메서드를 재정 의하여 전달 된 페이지를 확인하고 웹에서 열 수 있습니다. 브라우저 :

protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    base.OnNavigatedTo(e); 

    if (NavigationContext.QueryString.ContainsKey("Page") && NavigationContext.QueryString.ContainsKey("id")) 
    { 
     var page = NavigationContext.QueryString["Page"]; 
     var hashId = NavigationContext.QueryString["id"]; 

     yourWebBrowser.Navigate(new Uri(String.Format("/f{0}.html#{1}", page, hashId), UriKind.Relative)); 
    } 
} 

자세한 내용은 How to perform page navigation on Windows Phone에서 Passing paramenters 섹션을 참조하십시오.

+0

화려한 코드 조각. 한 가지 더 의심 스럽다. 내 응용 프로그램에서 선언 된'id'로 이동하고 싶습니다. 예 : 'f1.html # 34'. 어떻게해야합니까? –

+0

당신도 querystring으로 넘겨 줄 수있을 것입니다 :'NavigationService.Navigate (new Uri ("/ webview.xaml? Page ="+ showFile + "& id ="+ yourId, UriKind.Relative)); ' – anderZubi

+0

'& id =' 작동하지 않습니다 –

관련 문제