C# 将长列表选择器绑定到POST方法的结果

C# 将长列表选择器绑定到POST方法的结果,c#,web-services,windows-phone-8,longlistselector,C#,Web Services,Windows Phone 8,Longlistselector,我正在尝试将数据发布到服务器,并获得将其绑定到长列表选择器的响应。代码如下: public class TestData { private string _LikeNum, _CommentNum, _HyperLinkTitle, _HyperLinkNavigationLink, _BrandImage, _PostImage, _PostDate, _PostTitle, _PostDescription, _PostID; public

我正在尝试将数据发布到服务器,并获得将其绑定到长列表选择器的响应。代码如下:

     public class TestData
    {
        private string _LikeNum, _CommentNum, _HyperLinkTitle, _HyperLinkNavigationLink, _BrandImage, _PostImage, _PostDate, _PostTitle, _PostDescription, _PostID;
        public string LikeNum { get { return _LikeNum; } set { _LikeNum = value; } }
        public string CommentNum { get { return _CommentNum; } set { _CommentNum = value; } }
        public string HyperLinkTitle { get { return _HyperLinkTitle; } set { _HyperLinkTitle = value; } }
        public string HyperLinkNavigationLink { get { return _HyperLinkNavigationLink; } set { _HyperLinkNavigationLink = value; } }
        public string BrandImage { get { return _BrandImage; } set { _BrandImage = value; } }
        public string PostImage { get { return _PostImage; } set { _PostImage = value; } }
        public string PostDate { get { return _PostDate; } set { _PostDate = value; } }
        public string PostTitle { get { return _PostTitle; } set { _PostTitle = value; } }
        public string PostDescription { get { return _PostDescription; } set { _PostDescription = value; } }
        public string PostID { get { return _PostID; } set { _PostID = value; } }
        public TestData(string LNum, string CNum, string HLTitle, string HLNaviagtionLink, string BImage, string PImage, string PDate, string PTitle, string PDescription, string PID)
        {
            this.LikeNum = LNum;
            this.CommentNum = CNum;
            this.HyperLinkTitle = HLTitle;
            this.HyperLinkNavigationLink = HLNaviagtionLink;
            this.BrandImage = BImage;
            this.PostImage = PImage;
            this.PostDate = PDate;
            this.PostTitle = PTitle;
            this.PostDescription = PDescription;
            this.PostID = PID;
        }
    }
    #region Lists of data
    List<string> LstBrandID = new List<string>();
    List<string> LstBrandName = new List<string>();
    List<string> LstBrandLongitude = new List<string>();
    List<string> LstBrandLatitude = new List<string>();
    List<string> LstPostID = new List<string>();
    List<string> LstPostTitle = new List<string>();
    List<string> LstPostDescription = new List<string>();
    List<string> LstPostDate = new List<string>();
    List<string> LstLikeNum = new List<string>();
    List<string> LstCommentNum = new List<string>();
    List<string> LstUserLike = new List<string>();
    List<string> LstCatName = new List<string>();
    List<string> LstUserFollow = new List<string>();
    #endregion
    ObservableCollection<TestData> DataList = new ObservableCollection<TestData>();
    string id;
    public Home()
    {
        InitializeComponent();
        id = PhoneApplicationService.Current.State["id"].ToString();
        try
        {
            GetPosts(id);
            myLLS.ItemsSource = DataList;
            for (int i = 1; i <= 10; i++)
            {
                DataList.Add(new TestData(LstLikeNum[i], LstCommentNum[i], LstBrandName[i], "SomePage.xaml", "SomeLink.com/data/" + LstBrandID[i], "SomeLink.com/data/" + LstPostID[i], LstPostDate[i], LstPostTitle[i], LstPostDescription[i], LstPostID[i]));
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
            throw;
        }

    }

    #region getting data
    void GetPosts(string UserID)
    {
        WebClient webclient = new WebClient();
        Uri uristring = new Uri("SomeLink.com");
        webclient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
        string postJsonData = string.Empty;
        postJsonData += "userId=" + UserID;
        webclient.UploadStringAsync(uristring, "POST", postJsonData);
        webclient.UploadStringCompleted += webclient_UploadStringCompleted;
    }

    void webclient_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
    {
        try
        {
            if (e.Result != null)
            {
                string response = e.Result.ToString();
                JArray a = JArray.Parse(response);
                foreach (JObject o in a.Children<JObject>())
                {
                    foreach (JProperty p in o.Properties())
                    {
                        string name = p.Name;
                        string value = p.Value.ToString();
                        if (name == "brandId")
                        {
                            LstBrandID.Add(value);
                        }
                        else if (name == "brandName")
                        {
                            LstBrandName.Add(value);
                        }
                        else if (name == "brandLongitude")
                        {
                            LstBrandLongitude.Add(value);
                        }
                        else if (name == "brandLatitude")
                        {
                            LstBrandLatitude.Add(value);
                        }
                        else if (name == "postId")
                        {
                            LstPostID.Add(value);
                        }
                        else if (name == "postTitle")
                        {
                            LstPostTitle.Add(value);
                        }
                        else if (name == "postDescription")
                        {
                            LstPostDescription.Add(value);
                        }
                        else if (name == "postDate")
                        {
                            LstPostDate.Add(value);
                        }
                        else if (name == "likeNum")
                        {
                            LstLikeNum.Add(value);
                        }
                        else if (name == "commentNum")
                        {
                            LstCommentNum.Add(value);
                        }
                        else if (name == "userLike")
                        {
                            LstUserLike.Add(value);
                        }
                        else if (name == "catName")
                        {
                            LstCatName.Add(value);
                        }
                        else if (name == "userFollow")
                        {
                            LstUserFollow.Add(value);
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }

    }
    #endregion
公共类TestData
{
私有字符串\u likum、\u CommentNum、\u HyperLinkTitle、\u HyperLinkNavigationLink、\u BrandImage、\u PostImage、\u PostDate、\u PostTitle、\u PostDescription、\u PostID;
公共字符串LIKEUM{get{return}LIKEUM;}集合{U LIKEUM=value;}
公共字符串CommentNum{get{return{u CommentNum;}set{{u CommentNum=value;}}
公共字符串HyperLinkTitle{get{return{uHyperlinkTitle;}set{{uHyperlinkTitle=value;}}
公共字符串HyperLinkNavigationLink{get{return{uHyperlinkNavigationLink;}set{{uHyperlinkNavigationLink=value;}}
公共字符串BrandImage{get{return}BrandImage;}set{BrandImage=value;}
公共字符串PostImage{get{return}u PostImage;}set{{u PostImage=value;}}
公共字符串PostDate{get{return}u PostDate;}set{{u PostDate=value;}}
公共字符串PostTitle{get{return}u PostTitle;}set{{u PostTitle=value;}}
公共字符串PostDescription{get{return{uPostDescription;}set{{uPostDescription=value;}}
公共字符串PostID{get{return}PostID;}set{{USPOSTID=value;}}
公共测试数据(字符串LNum、字符串CNum、字符串HLTitle、字符串HLNaviagtionLink、字符串BImage、字符串PImage、字符串PDate、字符串PTitle、字符串pddescription、字符串PID)
{
this.likum=LNum;
this.CommentNum=CNum;
this.HyperLinkTitle=HLTitle;
this.HyperLinkNavigationLink=hlNavigationLink;
this.BrandImage=BImage;
this.PostImage=PImage;
this.PostDate=PDate;
this.PostTitle=PTitle;
this.PostDescription=pddescription;
this.PostID=PID;
}
}
#区域数据列表
List LstBrandID=新列表();
List LstBrandName=新列表();
List LSTBrandLength=新列表();
List LstBrandLatitude=新列表();
List LstPostID=新列表();
List LstPostTitle=新列表();
List LstPostDescription=新列表();
List LstPostDate=新列表();
List lstlikeum=新列表();
List LstCommentNum=新列表();
List LstUserLike=新列表();
List LstCatName=新列表();
List LstUserFollow=新列表();
#端区
ObservableCollection DataList=新的ObservableCollection();
字符串id;
公共住宅()
{
初始化组件();
id=PhoneApplicationService.Current.State[“id”].ToString();
尝试
{
GetPosts(id);
myLLS.ItemsSource=数据列表;
对于
主页()中的(int i=1;i:

很好。您正在告诉您的LLS监视此数据源,并在插入新项时进行自我更新

for (int i = 1; i <= 10; i++)
{
    DataList.Add(new TestData(LstLikeNum[i], LstCommentNum[i], LstBrandName ...);
}

for(int i=1;我将您的列表绑定到
webclient\u UploadStringCompleted
中,并确保您至少返回10个帖子。非常感谢。这很有效!但是我如何才能为长列表选择器项创建“分页”之类的功能呢?
for (int i = 1; i <= 10; i++)
{
    DataList.Add(new TestData(LstLikeNum[i], LstCommentNum[i], LstBrandName ...);
}
void webclient_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e) {
    ...
    int i = 0;
    foreach (JObject o in a.Children<JObject>())
    {
        foreach (JProperty p in o.Properties())
        {
        ...
        }

        var testData = new TestData(LstLikeNum[i], LstCommentNum[i], ...);
        DataList.Add(testData);
        i++;
    }
}