首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >列表故障(UWP)

列表故障(UWP)
EN

Stack Overflow用户
提问于 2016-10-29 20:18:42
回答 1查看 91关注 0票数 0

我为UWP平台编写应用程序。

我在代码中使用了绑定。

下面是我的ViewModel的代码:

代码语言:javascript
运行
复制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Milano.Annotations;
using WooCommerceNET;
using WooCommerceNET.WooCommerce;
using Newtonsoft.Json;

namespace Milano.Classes
{
    public class InWorkViewModel: INotifyPropertyChanged
    {


        private List<LineItem> productList;
        public List<LineItem> ProductList
        {
            get { return productList; }
            set { productList = value; OnPropertyChanged(); }
        }

        private List<RootObject> ordersList;

        public List<RootObject> OrdersList
        {
            get { return ordersList; }
            set { ordersList = value; OnPropertyChanged(); }
        }


        private RootObject ordersChange;

        public RootObject OrdersChange
        {
            get { return ordersChange; }
            set { ordersChange = value; OnPropertyChanged(); }
        }

        private LineItem ordersChange2;

        public LineItem OrdersChange2
        {
            get { return ordersChange2; }
            set { ordersChange2 = value;OnPropertyChanged(); }
        }

        public  InWorkViewModel()
        {


            Inwork_down();
           // var interval = 100000;
            //UpdateWithImterwal(interval);


        }

        /* private async void UpdateWithImterwal(int interval)
         {


            // OrdersList.Clear();
           Inwork_down();

             await Task.Delay(interval).ContinueWith(_ => UpdateWithImterwal(interval));
         }*/
        public async void Inwork_down()
        {

            RestAPI rest = new RestAPI("http://simplegames.com.ua/wp-json/wc/v1/", "ck_9d64c027d2c5f81b8bed3342eeccc6d337be813d", "cs_60697b1e6cbdeb8d62d19e0765e339f8e3334754");
            WCObject wc = new WCObject(rest);
            //Get all products
            var orders = await wc.GetOrders(new Dictionary<string, string>() {
                          { "per_page", "100" }, { "status","processing"} }); // Dodelat filtr dlaya teh chto v  rabote


            string products = orders.ToFormattedJsonString();
            Debug.WriteLine(products);


            List<RootObject> rootObjectData = JsonConvert.DeserializeObject<List<RootObject>>(products);


            OrdersList = new List<RootObject>(rootObjectData);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    public class Billing
    {
        public string first_name { get; set; }
        public string last_name { get; set; }
        public string company { get; set; }
        public string address_1 { get; set; }
        public string address_2 { get; set; }
        public string city { get; set; }
        public string state { get; set; }
        public string postcode { get; set; }
        public string country { get; set; }
        public string email { get; set; }
        public string phone { get; set; }
    }

    public class Shipping
    {
        public string first_name { get; set; }
        public string last_name { get; set; }
        public string company { get; set; }
        public string address_1 { get; set; }
        public string address_2 { get; set; }
        public string city { get; set; }
        public string state { get; set; }
        public string postcode { get; set; }
        public string country { get; set; }
    }

    public class LineItem
    {
        public int id { get; set; }
        public string name { get; set; }
        public string sku { get; set; }
        public int product_id { get; set; }
        public int variation_id { get; set; }
        public int quantity { get; set; }
        public string tax_class { get; set; }
        public double price { get; set; }
        public double subtotal { get; set; }
        public double subtotal_tax { get; set; }
        public double total { get; set; }
        public double total_tax { get; set; }
        public List<object> taxes { get; set; }
        public List<object> meta { get; set; }
    }

    public class ShippingLine
    {
        public int id { get; set; }
        public string method_title { get; set; }
        public string method_id { get; set; }
        public double total { get; set; }
        public double total_tax { get; set; }
        public List<object> taxes { get; set; }
    }

    public class RootObject
    {
        public int id { get; set; }
        public int parent_id { get; set; }
        public string status { get; set; }
        public string order_key { get; set; }
        public string currency { get; set; }
        public string version { get; set; }
        public bool prices_include_tax { get; set; }
        public string date_created { get; set; }
        public string date_modified { get; set; }
        public int customer_id { get; set; }
        public double discount_total { get; set; }
        public double discount_tax { get; set; }
        public double shipping_total { get; set; }
        public double shipping_tax { get; set; }
        public double cart_tax { get; set; }
        public double total { get; set; }
        public double total_tax { get; set; }
        public Billing billing { get; set; }
        public Shipping shipping { get; set; }
        public string payment_method { get; set; }
        public string payment_method_title { get; set; }
        public string transaction_id { get; set; }
        public string customer_ip_address { get; set; }
        public string customer_user_agent { get; set; }
        public string created_via { get; set; }
        public string customer_note { get; set; }
        public string date_completed { get; set; }
        public string date_paid { get; set; }
        public string cart_hash { get; set; }
        public List<LineItem> line_items { get; set; }
        public List<object> tax_lines { get; set; }
        public List<ShippingLine> shipping_lines { get; set; }
        public List<object> fee_lines { get; set; }
        public List<object> coupon_lines { get; set; }
    }

我的问题出在哪里。

如你所见,我在类中有这个public List<LineItem> line_items { get; set; }。我需要从rootObject中获取这个列表,并像绑定RootObject一样绑定其中的值。

那么,什么是应用程序中的视图逻辑。我将一些数据绑定到左侧面板,当我点击左侧面板上的element时,我使右侧面板可见,在那里我从public RootObject OrdersChange绑定в属性。

以下是一些屏幕:

我怎么能做到这一点?

EN

回答 1

Stack Overflow用户

发布于 2016-10-31 01:21:39

如果我理解正确的话,您希望将两个类绑定到一个视图。如果是这样,我可以建议两种方法: 1)为这两个类创建基类。

代码语言:javascript
运行
复制
    class BaseClass { }

class RootObject: BaseClass { }

class LineItem : BaseClass { }

class MainViewModel
{
    public List<LineItem> ProductList { get; set; }
    public List<RootObject> OrdersList { get; set; }

    public BaseClass LeftListViewSelectedItem { get; set; }
}

2)也可以将属性LeftListViewSelectedItem的返回类型设置为object。对于绑定来说,无论你返回什么都无关紧要。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40319012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档