开发者

Windows Phone Emulator Functions Properly, Debugging or Deploying to Device Does Not

开发者 https://www.devze.com 2023-02-24 16:52 出处:网络
I am developing a very simple application that parses an XML feed, does some formatting and then displays it in a TextBlock. I\'ve added a hyperLink (called \"More..) to the bottom of the page (ideall

I am developing a very simple application that parses an XML feed, does some formatting and then displays it in a TextBlock. I've added a hyperLink (called "More..) to the bottom of the page (ideally this would be added to the end of the TextBlock after the XML has been parsed) to add more content by changing the URL of the XML feed to the next page.

The issue I'm experiencing is an odd one as the program works perfectly when in the Windows Phone 7 Emulator, but when I deploy it to the device or debug on the device, it works for the first click of the "More..." button, but the ones after the first click just seem to add empty space into the application when deployed or debugged from the device.

I'm using a Samsung Focus (NoDo) and originally thought this may have had to do with the fact that I may not have had the latest developer tools. I've made sure that I am running the latest version of Visual Studio and am still running into the issue.

Here are some snippets of my code to help out.

I've declared the clickCount variable here:

public partial class MainPage : PhoneApplicationPage

 开发者_JAVA百科    //set clickCount to 2 for second page  
     int clickCount = 2;

Here is the snippet of code I use to parse the XML file:

    void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            ListBoxItem areaItem = null;

            StringReader stream = new StringReader(e.Result);
            XmlReader reader = XmlReader.Create(stream);
            string areaName = String.Empty;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "example")
                    {
                        areaName = reader.ReadElementContentAsString();

                        areaItem = new ListBoxItem();
                        areaItem.Content = areaName;
                        textBlock1.Inlines.Add(areaName);
                        textBlock1.Inlines.Add(new LineBreak());

                    }
                }
            }

        }
    }

and the code for when the hyperLink button is clicked:

    private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
    {

        int stringNum = clickCount;

        //URL is being incremented each time hyperlink is clicked
        string baseURL = "http://startofURL" + stringNum + ".xml";

        Uri url = new Uri(baseURL, UriKind.Absolute);
        WebClient client = new WebClient();

        client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
        client.DownloadStringAsync(url);

        //increment page number
        clickCount = clickCount + 1;

    }


It feels like there's a little more debugging to do here.

Can you test where exactly this is going wrong?

  • is it the click that is not working on subsequent attempts?
  • is it the HTTP load which is failing?
  • is it the adding of inline text which is failing?

Looking at it, I suspect it's the last thing. Can you check that your TextBlock is expecting Multiline text? Also, given what you've written (where you don't really seem to be making use of the Inline's from the code snippet I've seen), it might be easier to append add the new content to a ListBox or a StackPanel rather than to the inside of the TextBlock - ListBox's especially have some benefit in terms of Virtualizing the display of their content.

0

精彩评论

暂无评论...
验证码 换一张
取 消