×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Super Contributor
    Join Date
    Nov 2010
    Posts
    1,280

    Cool Error:An object reference is required for the non-static field, method

    [B]Error 3 An object reference is required for the non-static field, method, or property 'System.Windows.Navigation.NavigationContext.QueryString.get' C:\Users\shravan\documents\visual studio 2012\Projects\YuppTV2\YuppTV2\Dates.xaml.cs




    Error screenshot as below:


    Click image for larger version. 

Name:	newscrshot.jpg 
Views:	405 
Size:	92.0 KB 
ID:	1608

    code is as follows:



    Code:
    using System.Windows.Navigation;
    
    using Microsoft.Phone.Shell;
    using YuppTV2.Resources;
    using System;
    using System.Collections.Generic;
    using System.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;
    using System.Xml.Linq;
    using System.IO.IsolatedStorage;
    using Microsoft.Phone.Net.NetworkInformation;
    
    
    
    using Microsoft.Web.Media.SmoothStreaming;
    using System.Windows.Threading;
    using System.Diagnostics;
    
    
    namespace YuppTV2
    {
       
             public partial class Dates : PhoneApplicationPage
        {
            //string id;
            string date;
            string emailid;
            string pass;
    
            public Dates()
            {
                InitializeComponent();
                this.Loaded += new RoutedEventHandler(Https2Completed);
            }
            private void Https2Completed(object sender, RoutedEventArgs e)
            {
                PageTitle.Text = NavigationContext.QueryString["desc"].ToString();
             
                GetDates();
            }
            private void GetDates()
            {
                if (NetworkInterface.NetworkInterfaceType != NetworkInterfaceType.None)
                {
                    if (NavigationContext.QueryString["pacId"].Length > 0 && NavigationContext.QueryString["chaId"].Length > 0)
                    {
                        WebClient wc = new WebClient();
                        wc.DownloadStringCompleted += Https2Completed;
                        wc.DownloadStringAsync(new Uri("http://www.yupptv.com/samsung/SamTVSubscription.aspx?samapikey=ert35346&samuid=SDK-VIRTUAL-DUID&wmthod=9&device=wp7"));
                    }
                }
                else
                {
                    MessageBox.Show("No network found");
                    txtDownload.Visibility = System.Windows.Visibility.Collapsed;
                    progressBar2.Visibility = System.Windows.Visibility.Collapsed;
                    //imgNetwork.Visibility = System.Windows.Visibility.Visible;
                }
            }
    
            private void Https2Completed(object sender, DownloadStringCompletedEventArgs e)
            {
                if (e.Error == null)
                {
                    XDocument loadedData = XDocument.Parse(e.Result, LoadOptions.None);
                    var data = from query in loadedData.Descendants("VodDate")
                               select new Packages2
                               {
                                   Dt = (string)query.Element("Date"),
                                   DispDt = (string)query.Element("DisplayDate")
                                
                               };
                    if (data.Count() > 0)
                    {
                        listBox.ItemsSource = data;
                    }
                    else
                    {
                        MessageBox.Show("No records found");
                    }
    
                    txtDownload.Visibility = System.Windows.Visibility.Collapsed;
                    progressBar2.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
            public class Packages2
            {
                string date;
                string displdate;
    
                  public string Dt
                {
                    get { return date; }
                    set { date = value; }
                }
                public string DispDt
                {
                    get { return displdate; }
                    set { displdate = value; }
                }
    
                private void txtDates_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
                {
                    // gets the stackpanel 
                    var parent = VisualTreeHelper.GetParent(sender as DependencyObject);
    
                    // gets the text box 
                    var child = VisualTreeHelper.GetChild(parent, 0);
    
                    var textBox = child as TextBlock;
                 
                  if (textBox != null)
                    {
                        date = textBox.Text;
                    }
                  NavigationService.Navigate(new Uri("/Programs.xaml?pacId=" + NavigationContext.QueryString["pacId"] + "&chaId=" + NavigationContext.QueryString["chaId"] + "&date=" + date.ToString() + "&uId=" + NavigationContext.QueryString["uId"] + "&pass=" + NavigationContext.QueryString["pass"] + "&desc=" + NavigationContext.QueryString["desc"], UriKind.Relative));
                }
           
            }
        }
    }

  2. #2
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Gurgaon,India
    Posts
    4,102

    Re: Error:An object reference is required for the non-static field, method

    Search - 'passing data between pages in Windows Phone'

  3. #3
    Regular Contributor
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    298

    Re: Error:An object reference is required for the non-static field, method

    First thing, you're calling NavigationContext on another class "Packages2" which is not the parent class (Page), then as far as I know, NavigationContext will throw a NullReferenceException if called outside OnNavigatedTo() event, so try to extract all the data you need on the "OnNavigatedTo" page event and store it on variables, then call those variables in your Uri string.

    I hope it helps

Similar Threads

  1. Replies: 4
    Last Post: 2010-10-24, 05:55
  2. undefine reference when using static lib
    By nire123 in forum Symbian
    Replies: 7
    Last Post: 2009-10-11, 21:50
  3. using non static member in static method
    By sk.panda in forum Symbian
    Replies: 2
    Last Post: 2009-05-22, 13:32
  4. Replies: 9
    Last Post: 2007-03-21, 08:57
  5. static data member gives undefined reference error
    By cmalu in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2004-11-30, 17:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×