2010-11-02 95 views
0

馬庫斯在這裏。我遇到了一個難以解決的問題。顯然,我有一個連接到dotnetzonereader的Windows 7手機編碼的例子。那麼我試圖改變網址到www.google.com,但它無法這樣做。在這裏,我不是指訪問www.google.com的Windows 7模擬器中的Internet Explorer,但是我正在討論訪問Internet的應用程序。這是我從網上獲得的代碼的一個例子。我試過改變這個部分> dzoneRss.DownloadStringAsync(new Uri(「http://feeds.dzone.com/zones/dotnet」)); to dzoneRss.DownloadStringAsync(new Uri(「http://google.com」)); 但仍有錯誤。任何一種靈魂都會在這裏幫助我完成這個T_T。感謝人們。真的三江源將Windows 7手機模擬器連接到自己的網站?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Xml.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 



namespace DotNetZoneReader 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     public MainPage() 
     { 
      InitializeComponent(); 

      SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape; 
     } 

     private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) 
     { 

     } 

     private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) 
     { 

     } 

     private void storyList_SelectionChanged(object sender, SelectionChangedEventArgs e) 
     { 

     } 

     private void button1_Click(object sender, RoutedEventArgs e) 
     { 
      var dzoneRss = new WebClient(); 
      dzoneRss.DownloadStringCompleted += dzoneRss_DownloadStringCompleted; 
      dzoneRss.DownloadStringAsync(new Uri("http://feeds.dzone.com/zones/dotnet")); 
     } 
     private void dzoneRss_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
     { 
      if (e.Error != null) return; 
      XElement xmlStories = XElement.Parse(e.Result); 
      XNamespace dz = "http://www.developerzone.com/modules/dz/1.0"; 
      storyList.ItemsSource = from story in xmlStories.Descendants("item") 
            select new FeedItem 
            { 
             Title = story.Element("title").Value, 
             Description = story.Element("description").Value, 
             Link = story.Element("link").Value, 
             PublishDate = Convert.ToDateTime(story.Element(dz + "submitDate").Value).ToString("dd-MMM"), 
             Author = story.Element(dz + "submitter").Element(dz + "username").Value, 
             AuthorImageUrl = story.Element(dz + "submitter").Element(dz + "userimage").Value 
            }; 
     } 
     public class FeedItem 
     { 
      public string Title { get; set; } 
      public string Description { get; set; } 
      public string Link { get; set; } 
      public string PublishDate { get; set; } 
      public string Author { get; set; } 
      public string AuthorImageUrl { get; set; } 
     } 
    } 
} 
+0

你遇到了什麼確切的錯誤?你想做什麼?如果您正在加載的頁面沒有定義XML名稱空間(並且不是XML格式),那麼您肯定會得到一個錯誤。 – 2010-11-02 04:21:26

+0

嗨馬庫斯,你的代碼爲你工作之前,你改變的網址?你從哪一行得到的錯誤是什麼? – 2010-11-02 04:22:57

+0

感謝Dennis和Mick的回答。正如我所提到的,這是我從網上檢索到的dotnetzonereader的示例。如果你們可以將我上面提到的代碼複製到Microsoft Visual Studio 2010 Express For Windows Phone中,那將會很棒。一旦我按下刷新按鈕,它使我能夠看到網頁http://feeds.dzone.com/zones/dotnet。不過,我試圖改變它,讓我訪問谷歌。我的問題是我必須改變哪部分代碼,然後我才能訪問谷歌?謝謝@米克@丹尼爾 – marcus 2010-11-02 07:42:39

回答

0

要訪問谷歌,你可以通過把你的頁面上的WebBrowser控件和設置源點在Web瀏覽器的加載事件,谷歌做到這一點很簡單。例如

private void webBrowser1_Loaded(object sender, RoutedEventArgs e) { 
     webBrowser1.Navigate(new Uri("http://www.google.com/", UriKind.Absolute)); 
    } 

您鏈接的代碼做了不同的事情,根據您的要求,你不需要,不一定與谷歌的網站兼容。

您可以在一個空的Windows Phone應用程序項目中完成上述操作。

+0

@米克N謝謝你的回答,過去幾天都很忙。對不起,如果我現在在這個問題上太討厭了,因爲我並不熟悉Express電話的視覺工作室。我如何設置源代碼?如果你可以進一步細化,會不會有可能?對不起,麻煩您了。我試過這樣做。 – marcus 2010-11-08 01:08:52

+0

@ Mick N using System; using System.Collections.Generic;使用System.Linq的 ;使用System.Net的 ;使用System.Windows的 ; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; 命名空間WindowsPhoneApplication2 { 公共部分類的MainPage:的PhoneApplicationPage { 公共的MainPage() { 的InitializeComponent(); – marcus 2010-11-08 01:09:44

+0

@ Mick N SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape; } private void webBrowser1_Loaded(object sender,RoutedEventArgs e) webbrowser1.Navigate(new Uri(「http://www.google.com/」絕對)); } } } – marcus 2010-11-08 01:16:19

相關問題