WP8问题与html敏捷包

时间:2014-04-01 06:34:53

标签: windows-phone-8 html-agility-pack

这是我用来从网站获取字符串内容的函数..问题是在首先执行时我无法获取字符串内容(App.Data2 = userprofile.InnerText;),因为它跳到下一行({{1} })这样我得到一个空字符串。如果我记得这个函数我可以得到字符串。有没有可能解决这个问题我需要第一次自动获取字符串值

这是我的Page.cs代码:

App.savecontent(App.Data2);

这是我的App.Xaml.cs文件:

namespace Project_Future1
{
    public partial class Page1 : PhoneApplicationPage
    {    
        public  Page1()
        {
            InitializeComponent();
            {
                string url = "http://www.astrosage.com/horoscope/daily-";
                HtmlWeb.LoadAsync(url + App.Data + "-horoscope.asp", DownLoad);
            } 
            data();

            App.loadContent();
            change2();
        }

        public void change2()
        {
            try
            {
              Util.LiveTile.UpdateLiveTile(App.Data2);
            }
            catch (Exception)
            {
            }
        }

        public void DownLoad(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Error == null)
            {
                HtmlDocument doc =  e.Document;
                if (doc != null)
                {
                    var userprofile = doc.DocumentNode.SelectSingleNode("//div[@class = 'ui-large-content']");

                    App.Data2 =   userprofile.InnerText;
                    App.savecontent(App.Data2); 
                }
            } 
        }

        private void data()
        {
            SelectedSign.Text = App.Data;
            SSContent.Text = App.Data2;
        }

        private void Refresh_click(object sender, EventArgs e)
        {
            SSContent.Text = App.Data2;
        }


        private void Fb_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/FB.xaml", UriKind.Relative));
        }
    }
}

这是我从存储中加载内容的代码:

public static void savecontent(string save)
{
    try
    {
        if (!string.IsNullOrEmpty(appFileName1))
        {
            IsolatedStorageFile oIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
            oIsolatedStorage.CreateDirectory(appFolder1);
            StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream(appFolder1 + "\\" + appFileName1, FileMode.OpenOrCreate, oIsolatedStorage));

            writeFile.WriteLine(save);
            writeFile.Close();
        }
    }
    catch (Exception)
    {
        throw;
    }
}

0 个答案:

没有答案