protected override async void OnNavigatedTo(NavigationEventArgs e) { goodsList.Clear(); try { List<GoodsInfo> list = e.Parameter as List<GoodsInfo>; if (null != list) { goodsList = list; } Windows.Storage.StorageFolder storageFolder = ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile shoppingCartStorageFile = await storageFolder.GetFileAsync("ShoppingCart.xml"); XmlDocument doc = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(shoppingCartStorageFile); IXmlNode root = null; foreach (var item in doc.ChildNodes) { if (item.NodeName.Equals("goods")) { root = item; break; } } if (null != root) { foreach (var goods in root.ChildNodes) { if (goods.NodeName.Equals("item")) { string imgUrl = goods.SelectSingleNode("img").InnerText; string singlePrice = goods.SelectSingleNode("price").InnerText; string name = goods.SelectSingleNode("productName").InnerText; string count = goods.SelectSingleNode("count").InnerText; string imagename = goods.SelectSingleNode("imageName").InnerText; bool exist = false; foreach (var item in goodsList) { if (item.name.Equals(name) && item.imgUri.Equals(imgUrl)) { item.count = item.count + Convert.ToInt32(count); exist = true; break; } } if (!exist) { GoodsInfo info = new GoodsInfo(); StorageFile file = await StorageFile.GetFileFromPathAsync(imgUrl); using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { BitmapImage image = new BitmapImage(); image.SetSource(fileStream); info.img = image; } info.name = name; info.price = singlePrice; info.count = Convert.ToInt32(count); info.imageName = imagename; info.imgUri = imgUrl; goodsList.Add(info); } } } } int index = 0; foreach (var item in goodsList) { ShopCartPanel panel = new ShopCartPanel(); panel.Picture = item.brush; panel.GoodsName = item.name; panel.PictureName = item.imageName; panel.GoodsCount = item.count; panel.Price = item.price; panel.Name = item.imgUri + item.name; panel.PictureURL = item.imgUri; CheckBox check = new CheckBox(); if(null != checkboxStyle) { check.SetValue(StyleProperty,checkboxStyle); } check.Checked += CheckBox_Checked; check.Unchecked += CheckBox_Unchecked; panel.Check = check; Button btnAdd = new Button(); btnAdd.Click += Add_Click; Button btnDecrease = new Button(); btnDecrease.Click += Decrease_Click; panel.ButtonAdd = btnAdd; panel.ButtonDecrease = btnDecrease; panel.PictureWith = PicWidth; if(index > 0 && goodsPanels.ContainsKey(index - 1)) { panel.SetValue(RelativePanel.RightOfProperty, goodsPanels[index - 1].Name); } else { panel.SetValue(RelativePanel.AlignLeftWithPanelProperty, true); } panel.SetValue(RelativePanel.AlignTopWithPanelProperty, true); goods.Children.Add(panel); goodsPanels.Add(index++,panel); } ResetPicturePanelPositon(); } catch(Exception ex) { #if DEBUG System.Diagnostics.Debug.WriteLine(ex.Message); #endif } }