示例#1
0
        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
            }            
        }
示例#2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            object obj = e.Parameter;
            if (null != obj)
            {
                string path = obj as string;
                imgPath = path;
                int index = 0;
                while (index >= 0)
                {
                    index = path.IndexOf('\\');
                    if (index >= 0)
                    {
                        path = path.Substring(index + 1);
                    }
                }
                index = path.IndexOf('.');
                if(index < 0)
                {
                    imageName = path;
                }
                else
                {
                    imageName = path.Substring(0, index);
                }
                
                
                StorageFile file = await StorageFile.GetFileFromPathAsync(imgPath);
                using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    BitmapImage image = new BitmapImage();
                    image.SetSource(fileStream);
                    source = image;
                }
                InkCanvas inkCanvas = new InkCanvas();
                inkCanvas.InkPresenter.StrokeContainer.Clear();
                var stream = await file.OpenSequentialReadAsync();
                if (null != stream)
                {
                    try
                    {
                        await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream);
                        if (inkCanvas.InkPresenter.StrokeContainer.GetStrokes().Count != 0)
                        {
                            isInkPic = true;
                        }
                    }
                    catch (Exception ex)
                    {
#if DEBUG
                        System.Diagnostics.Debug.WriteLine(ex.Message);
#endif
                        isInkPic = false;
                    }
                }
            }
            if (null != source)
            {
                ResourceDictionary dic = Application.Current.Resources;
                IList<ResourceDictionary> dics = dic.MergedDictionaries;
                ResourceDictionary resource = null;
                foreach(var item in dics)
                {
                    if(item.Source.AbsolutePath.Contains("/Files/Styles/Styles.xaml"))
                    {
                        resource = item;
                        break;
                    }

                }
                object style = null;
                if(null != resource)
                {
                                       
                    resource.TryGetValue("CheckBoxStyle", out style);
                }               

                ImageBrush brush = new ImageBrush();
                brush.ImageSource = source;
                //item 1
                GoodsPanel panel1 = new GoodsPanel();
                panel1.PictureWith = PicWidth;
                CheckBox check1 = new CheckBox();
                //check1.SetValue(StyleProperty,);
                check1.Checked += CheckBox_Checked;
                check1.Unchecked += CheckBox_Unchecked;
                if((style as Style) != null)
                {
                    check1.SetValue(StyleProperty, style);
                }
                panel1.Check = check1;
                panel1.PictureBrush = brush;
                panel1.GoodsName = "白杯子";
                panel1.Price = "¥35";
                panel1.PicturePath = imgPath;
                goodsPanels.Add(0,panel1);
                panel1.SetValue(RelativePanel.AlignLeftWithPanelProperty,true);
                panel1.SetValue(RelativePanel.AlignTopWithPanelProperty,true);
                goodsPanel.Children.Add(panel1);

                //item 2
                GoodsPanel panel2 = new GoodsPanel();
                panel2.PictureWith = PicWidth;
                CheckBox check2 = new CheckBox();
                //check1.SetValue(StyleProperty,);
                check2.Checked += CheckBox_Checked;
                check2.Unchecked += CheckBox_Unchecked;
                panel2.Check = check2;
                if ((style as Style) != null)
                {
                    check2.SetValue(StyleProperty, style);
                }
                panel2.PictureBrush = brush;
                panel2.GoodsName = "黑杯子";
                panel2.Price = "¥35";
                panel2.PicturePath = imgPath;
                goodsPanels.Add(1, panel2);
                panel2.SetValue(RelativePanel.RightOfProperty, panel1.Name);
                panel2.SetValue(RelativePanel.AlignTopWithPanelProperty, true);
                goodsPanel.Children.Add(panel2);

                //item 3
                GoodsPanel panel3 = new GoodsPanel();
                panel3.PictureWith = PicWidth;
                CheckBox check3 = new CheckBox();
                //check1.SetValue(StyleProperty,);
                check3.Checked += CheckBox_Checked;
                check3.Unchecked += CheckBox_Unchecked;
                panel3.Check = check3;
                if ((style as Style) != null)
                {
                    check3.SetValue(StyleProperty, style);
                }
                panel3.PictureBrush = brush;
                panel3.GoodsName = "白T恤";
                panel3.Price = "¥86";
                panel3.PicturePath = imgPath;
                goodsPanels.Add(2, panel3);
                panel3.SetValue(RelativePanel.RightOfProperty, panel2.Name);
                panel3.SetValue(RelativePanel.AlignTopWithPanelProperty, true);
                goodsPanel.Children.Add(panel3);

                //item 4
                GoodsPanel panel4 = new GoodsPanel();
                panel4.PictureWith = PicWidth;
                CheckBox check4 = new CheckBox();
                //check1.SetValue(StyleProperty,);
                check4.Checked += CheckBox_Checked;
                check4.Unchecked += CheckBox_Unchecked;
                panel4.Check = check4;
                if ((style as Style) != null)
                {
                    check4.SetValue(StyleProperty, style);
                }
                panel4.PictureBrush = brush;
                panel4.GoodsName = "黑T恤";
                panel4.Price = "¥86";
                panel4.PicturePath = imgPath;
                goodsPanels.Add(3, panel4);
                panel4.SetValue(RelativePanel.RightOfProperty, panel3.Name);
                panel4.SetValue(RelativePanel.AlignTopWithPanelProperty, true);
                goodsPanel.Children.Add(panel4);
                ResetPicturePanelPositon();
            }
        }