2

我正在尝试通过restsharp将数据从用户传输到服务器。下面是我使用的代码。我收到“当前上下文中不存在名称‘InitializeComponent’”的错误消息

我该如何调试?有没有逻辑错误?

'using System;
 using System.Net;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Documents;
 using System.Windows.Ink;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Animation;
 using System.Windows.Shapes;
 using Microsoft.Phone.Controls;
 using RestSharp;
 using Newtonsoft.Json.Linq;
 using Newtonsoft.Json;
 using System.Text.RegularExpressions;
 using System.Collections.Generic;
 using System.Linq;


 namespace Miser_sApp
 {
     public class RestSharp
     {
         public partial class SearchResults : PhoneApplicationPage
         {
             public static float _latitude, _longitude;
             public static DateTime _date, _time;
             public static string _name, _details;
             public static int _number, _amount, _uid;
             RestClient client;
             RestRequest request;

             int index;
             connect Connect;
             public SearchResults()
             {
                 InitializeComponent();
                 load();

             }
             private RestClient InitializeX()
             {
                 var client = new RestClient("//localhost" + Panorama1.username1 +                "&pro_type=" + Panorama1.number1 + "&pro_name=" + Panorama1.details1 + "&lat=" + Panorama1.lat1 + "&lon=" + Panorama1.lon1);
                 return client;
                 // request = new RestRequest(Method.GET);
             }
             public void load()
             {
                 client = InitializeX();
                 //MessageBox.Show("InternalInitialize Done");
                 request = new RestRequest(Method.POST);

                 client.ExecuteAsync<connect>(request, (response) =>
                 {
                     //   MessageBox.Show(response.Data.ToString());
                     Connect = response.Data;
                     if (response.Data == null || Connect.last == null || Connect == null)
                     {
                         MessageBox.Show("NO ITEMS FOUND");
                         NavigationService.Navigate(new Uri("/Personal.xaml", UriKind.Relative));

                     }
                     // name1.Items.Add(rootObject3.Details[0].ProductName);
                     //results.Items.Clear();
                     //int i = 0;
                     else
                         foreach (var row3 in Connect.last)
                         {
                             results.Items.Add("NAME-" + row3.Name + '\n' + "Details-" + row3.Details + '\n' + "Date-" + row3.Date + '\n' + "Amount-" + row3.Amount + '\n' + "userId-" + row3.Uid + '\n' + "---------------------------------------------------------------");
                         }
                 });

             }




             private void Button_Click(object sender, RoutedEventArgs e)
             {

                 Konnect d = Connect.last[index];
                 _name = d.Name;
                 _date = d.Date;
                 _time = d.Time;
                 _uid = d.Uid;
                 _amount = d.Amount;
                 _details = d.Details;
                 _latitude = d.Latitude;
                 _longitude = d.Longitude;

                 NavigationService.Navigate(new Uri("/Panaroma1.xaml", UriKind.Relative));


             }

             private void results_SelectionChanged(object sender, SelectionChangedEventArgs e)
             {
                 index = results.SelectedIndex;
             }

         }
         public class Konnect
         {
             public string Name { get; set; }
             public DateTime Date { get; set; }
             public DateTime Time { get; set; }
             public int Uid { get; set; }
             public String Details { get; set; }
             public int Amount { get; set; }
             public float Latitude { get; set; }
             public float Longitude { get; set; }
         }

         public class connect
         {
             public List<Konnect> last { get; set; }
         }

     }
 }
4

1 回答 1

0

这意味着 InitializeComponent(); 方法不存在。在下面的代码中。这可能是一个参考问题。这也可能意味着设计器文件有问题,因为设计器支持需要它。您可以在运行调试器时尝试单步执行该方法。还有错误发生在哪里?它是运行时错误还是在您尝试编译时发生?如果是编译错误,则表示该方法不存在,您要么需要创建它,要么在该方法中删除它的引用。

public SearchResults()
{
    InitializeComponent();
    load();

}

编辑:

您可能在 Designer.cs 文件中缺少此部分。请注意,这是基于 win 表单应用程序。您将需要研究此方法对于您尝试继承的类的位置。即PhoneApplicationPage类

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Text = "Form1";
    }
    #endregion

我刚刚创建了一个新应用程序,它会自动为我生成它。你必须删除它什么的。

于 2013-07-25T02:07:41.577 回答