Exemplo n.º 1
0
        void updateThemes()
        {
            themesPanel.Children.Clear();
            arr.Clear();

            bool themesFound = false;

            int i = 0;

            using (var stor = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
            {
                var dirs = stor.GetDirectoryNames("theme_*");
                foreach (string theme in dirs)
                {
                    try
                    {
                        TextBlock tbt = new TextBlock();
                        tbt.Text = theme;
                        themesPanel.Children.Add(tbt);

                        StreamReader reader;
                        XDocument xml;
                        using (var str = stor.OpenFile(theme + "/apps.txt", FileMode.Open))
                        {
                            reader = new StreamReader(str);
                            xml = XDocument.Load(reader);
                        }

                        StackPanel apppanel = new StackPanel();
                        int appi = 0;
                        foreach (XElement application in xml.Descendants("application"))
                        {
                            if (appi == 0)
                            {
                                apppanel = new StackPanel();
                                apppanel.Orientation = System.Windows.Controls.Orientation.Horizontal;
                                themesPanel.Children.Add(apppanel);
                            }
                            appentry app = new appentry();
                            app.name = application.Attribute(XName.Get("name")).Value;
                            app.guid = application.Attribute(XName.Get("guid")).Value;
                            app.image = theme + "/" + application.Attribute(XName.Get("image")).Value;

                            Image img = new Image();

                            using (var str = stor.OpenFile(app.image, FileMode.Open))
                            {
                                BitmapImage bmp = new BitmapImage();
                                bmp.SetSource(str);
                                img.Source = bmp;
                            }
                            img.Width = 170;
                            img.Height = 170;
                            img.FlowDirection = System.Windows.FlowDirection.LeftToRight;
                            img.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;

                            img.Margin = new Thickness(2, 2, 2, 2);

                            img.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(img_Tap);

                            apppanel.Children.Add(img);

                            img.Name = "tile___" + i;

                            arr.Add(app);

                            appi++;

                            i++;

                            if (appi > 1)
                            {
                                appi = 0;
                            }
                        }

                        themesFound = true;
                    }
                    catch
                    {
                    }
                }
            }

            if (!themesFound)
            {
                TextBlock tb = new TextBlock();
                tb.Text = "You have no themes downloaded!\nSwipe to the right to browse the gallery.";
                themesPanel.Children.Add(tb);
            }
        }
        void updateThemes()
        {
            themesPanel.Children.Clear();
            arr.Clear();

            bool themesFound = false;

            int i = 0;

            using (var stor = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
            {
                var dirs = stor.GetDirectoryNames("theme_*");
                foreach (string theme in dirs)
                {
                    try
                    {
                        TextBlock tbt = new TextBlock();
                        tbt.Text = theme;
                        themesPanel.Children.Add(tbt);

                        StreamReader reader;
                        XDocument    xml;
                        using (var str = stor.OpenFile(theme + "/apps.txt", FileMode.Open))
                        {
                            reader = new StreamReader(str);
                            xml    = XDocument.Load(reader);
                        }

                        StackPanel apppanel = new StackPanel();
                        int        appi     = 0;
                        foreach (XElement application in xml.Descendants("application"))
                        {
                            if (appi == 0)
                            {
                                apppanel             = new StackPanel();
                                apppanel.Orientation = System.Windows.Controls.Orientation.Horizontal;
                                themesPanel.Children.Add(apppanel);
                            }
                            appentry app = new appentry();
                            app.name  = application.Attribute(XName.Get("name")).Value;
                            app.guid  = application.Attribute(XName.Get("guid")).Value;
                            app.image = theme + "/" + application.Attribute(XName.Get("image")).Value;

                            Image img = new Image();

                            using (var str = stor.OpenFile(app.image, FileMode.Open))
                            {
                                BitmapImage bmp = new BitmapImage();
                                bmp.SetSource(str);
                                img.Source = bmp;
                            }
                            img.Width               = 170;
                            img.Height              = 170;
                            img.FlowDirection       = System.Windows.FlowDirection.LeftToRight;
                            img.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;

                            img.Margin = new Thickness(2, 2, 2, 2);

                            img.Tap += new EventHandler <System.Windows.Input.GestureEventArgs>(img_Tap);

                            apppanel.Children.Add(img);

                            img.Name = "tile___" + i;

                            arr.Add(app);

                            appi++;

                            i++;

                            if (appi > 1)
                            {
                                appi = 0;
                            }
                        }

                        themesFound = true;
                    }
                    catch
                    {
                    }
                }
            }


            if (!themesFound)
            {
                TextBlock tb = new TextBlock();
                tb.Text = "You have no themes downloaded!\nSwipe to the right to browse the gallery.";
                themesPanel.Children.Add(tb);
            }
        }