列表问题(UWP)

时间:2016-10-29 12:18:42

标签: c# visual-studio uwp

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

我在代码中使用Binding。

这里是我的ViewModel的代码:

div{
           margin-left: 50%;   
}

我的问题在哪里。

如你所见,我在课堂上有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; } } 。我需要从RootObject中获取这个列表,并像在rootObject中一样为其中的值创建Binding。

那么应用程序中View的逻辑是什么。我将一些数据添加到左侧面板,当我点击左侧面板上的元素时,我显示右侧面板,我在public List<LineItem> line_items { get; set; }绑定属性。

以下是一些屏幕:

Left List

Right List

我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您需要将bind 2类绑定到一个视图。如果是这样,我可以建议两种方式: 1)为这2个类创建基类。

    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。无论你返回什么,都可以绑定它。