private void CreateDragVisual()
        {
            ClearDragVisual();

            var bitmap = new System.Windows.Media.Imaging.WriteableBitmap(this, null);
            bitmap.Render(this, null);
            bitmap.Invalidate();

            _dragVisual = new System.Windows.Controls.Image();
            _dragVisual.Source = bitmap;

            // find topmost canvas.. (so we can add the drag visual as a child
            // and ensure that it is on top of everything)
            //
            var canvas = this.GetTopmostParentOfType<Canvas>();

            canvas.Children.Add(_dragVisual);

            var point = this.GetRelativePosition(canvas);

            _dragVisual.SetValue(Canvas.TopProperty, point.Y);
            _dragVisual.SetValue(Canvas.LeftProperty, point.X);

            // Really make sure the drag visual is on top
            //
            Canvas.SetZIndex(_dragVisual, Int16.MaxValue);
        }
Beispiel #2
0
        public System.Windows.Media.Imaging.WriteableBitmap ToBitmap()
        {
            var bmp = new System.Windows.Media.Imaging.WriteableBitmap(Width, Height);

            bmp.SetSource(new MemoryStream(Pixels));
            bmp.Invalidate();
            return(bmp);
        }
Beispiel #3
0
 public System.Windows.Media.Imaging.WriteableBitmap ToBitmap()
 {
     var bmp = new System.Windows.Media.Imaging.WriteableBitmap(Width, Height);
      bmp.SetSource(new MemoryStream(Pixels));
      bmp.Invalidate();
      return bmp;
 }
        void regenList()
        {
            /*
             * listBox1.Items.Clear();
             * foreach (appentry app in curMenu.apps)
             * {
             *  listBox1.Items.Add(app.name);
             * }
             */
            stackPanel1.Children.Clear();
            Rectangle rect = new Rectangle();

            rect.Width  = 62;
            rect.Height = 62;
            rect.Fill   = new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"]);
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                int y = 0;
                foreach (appentry app in curMenu.apps)
                {
                    try
                    {
                        System.Windows.Media.Imaging.WriteableBitmap wb = new System.Windows.Media.Imaging.WriteableBitmap(52, 52);
                        StackPanel panel = new StackPanel();

                        panel.Orientation = System.Windows.Controls.Orientation.Horizontal;

                        wb.Render(rect, null);

                        Image img = new Image();

                        img.Margin = new Thickness(1, 1, 10, 1);
                        img.Width  = 52;
                        img.Height = 52;
                        System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                        using (var file = store.OpenFile(app.guid + ".jpg", FileMode.Open, FileAccess.Read))
                        {
                            bmp.SetSource(file);
                        }
                        System.Diagnostics.Debug.WriteLine("apps/" + app.guid + ".jpg");
                        //bmp.SetSource(Application.GetResourceStream(new Uri("apps/" + app.guid + ".jpg", UriKind.Relative)).Stream);
                        //System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(new Uri("/" + app.image, UriKind.Relative));
                        img.Source = bmp;
                        wb.Render(img, null);
                        wb.Invalidate();
                        img.Source            = wb;
                        img.VerticalAlignment = System.Windows.VerticalAlignment.Center;

                        TextBlock text = new TextBlock();
                        text.Text              = app.name;
                        text.FontSize          = 30;
                        text.FontWeight        = FontWeights.Light;
                        text.VerticalAlignment = System.Windows.VerticalAlignment.Center;


                        //selectedApps.Add(cb);

                        //panel.Name = app.guid;
                        panel.Name   = "panel_" + y;
                        panel.Tap   += new EventHandler <GestureEventArgs>(panel_Tap);
                        panel.Margin = new Thickness(0, 1, 1, 10);

                        //panel.Children.Add(cb);
                        panel.Children.Add(img);
                        panel.Children.Add(text);

                        stackPanel1.Children.Add(panel);
                        y += 1;
                        //wb = null;
                    }
                    catch (Exception ez)
                    {
                        //MessageBox.Show(ez.Message + " " + ez.StackTrace);
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        ///  Calculates the bitmap dimensions and creates a new bitmap (if requested) with text drawn to
        ///  according to the settings applied to this text renderer.
        /// </summary>
        /// <param name="isRequestingBitmapInfoOnly">
        ///  <para>Set to true to not produce a bitmap and measure what the bitmap size will be instead.</para>
        ///  <para>Set to false to create a bitmap with text rendered to it.</para>
        /// </param>
        /// <returns>
        ///  <para>
        ///   Returns a result object with the requested bitmap data if flagged successful.
        ///   If the "isRequestingBitmapInfoOnly" argument was set true, then the result object will only provide
        ///   BitmapInfo and its Bitmap property will be null.
        ///  </para>
        ///  <para>
        ///   Returns a failure result object if there was an error, in which case the the result's Message property
        ///   would provide details as to what went wrong.
        ///  </para>
        /// </returns>
        private TextBitmapDataResult AcquireBitmapData(bool isRequestingBitmapInfoOnly)
        {
            // Do not continue if there is no text to render.
            if (fSettings.Text.Length <= 0)
            {
                return(new TextBitmapDataResult("No text to render."));
            }

            // Do not continue if not called on the main UI thread.
            // Note: Microsoft's WriteableBitmap.render() method used below can only be called on the main UI thread.
            if (System.Windows.Deployment.Current.Dispatcher.CheckAccess() == false)
            {
                return(new TextBitmapDataResult("Text can only be rendered on the main UI thread."));
            }

            // Do not continue if Corona is currently synchronized with the rendering thread.
            // Note: Calling the WriteableBitmap.render() while the rendering thread is blocked will cause deadlock.
            if (Direct3DSurfaceAdapter.IsSynchronizedWithRenderingThread)
            {
                return(new TextBitmapDataResult("Cannot render text while Corona is synchronized with the rendering thread."));
            }

            // Create a Xaml text control to be used to render text to a bitmap.
            var textBlock = new System.Windows.Controls.TextBlock();

            textBlock.Foreground        = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.White);
            textBlock.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            textBlock.Text = fSettings.Text;

            // Set up the font.
            if (string.IsNullOrEmpty(fSettings.FontSettings.FamilyName) == false)
            {
                if (string.IsNullOrEmpty(fSettings.FontSettings.FilePath) == false)
                {
                    System.IO.FileStream stream = null;
                    try
                    {
                        stream = System.IO.File.OpenRead(fSettings.FontSettings.FilePath);
                        textBlock.FontSource = new System.Windows.Documents.FontSource(stream);
                    }
                    catch (Exception) { }
                    finally
                    {
                        if (stream != null)
                        {
                            try
                            {
                                stream.Close();
                                stream.Dispose();
                            }
                            catch (Exception) { }
                        }
                    }
                }
                textBlock.FontFamily = new System.Windows.Media.FontFamily(fSettings.FontSettings.FamilyName);
            }
            textBlock.FontSize   = fSettings.FontSettings.PointSize;
            textBlock.FontWeight =
                fSettings.FontSettings.IsBold ? System.Windows.FontWeights.Bold : System.Windows.FontWeights.Normal;
            textBlock.FontStyle =
                fSettings.FontSettings.IsItalic ? System.Windows.FontStyles.Italic : System.Windows.FontStyles.Normal;

            // Set up the horizontal alignment of the text.
            if (fSettings.HorizontalAlignment == WinRT.Interop.Graphics.HorizontalAlignment.Center)
            {
                textBlock.TextAlignment = System.Windows.TextAlignment.Center;
            }
            else if (fSettings.HorizontalAlignment == WinRT.Interop.Graphics.HorizontalAlignment.Right)
            {
                textBlock.TextAlignment = System.Windows.TextAlignment.Right;
            }
            else
            {
                textBlock.TextAlignment = System.Windows.TextAlignment.Left;
            }

            // Set up multiline text wrapping if enabled.
            if (fSettings.BlockWidth > 0)
            {
                // Enable text wrapping at the given pixel width.
                textBlock.TextWrapping = System.Windows.TextWrapping.Wrap;
                textBlock.MaxWidth     = (double)fSettings.BlockWidth;
                textBlock.Width        = (double)fSettings.BlockWidth;
            }
            else
            {
                // Disable text wrapping.
                textBlock.TextWrapping = System.Windows.TextWrapping.NoWrap;
            }
            if (fSettings.BlockHeight > 0)
            {
                textBlock.MaxHeight = (double)fSettings.BlockHeight;
                textBlock.Height    = (double)fSettings.BlockHeight;
            }

            // Calculate a pixel width and height for the bitmap to render text to.
            int bitmapWidth = fSettings.BlockWidth;

            if (bitmapWidth <= 0)
            {
                bitmapWidth = (int)(Math.Ceiling(textBlock.ActualWidth) + 0.1);
            }
            if ((fSettings.ClipWidth > 0) && (bitmapWidth > fSettings.ClipWidth))
            {
                bitmapWidth = fSettings.ClipWidth;
            }
            int bitmapHeight = fSettings.BlockHeight;

            if (bitmapHeight <= 0)
            {
                bitmapHeight = (int)(Math.Ceiling(textBlock.ActualHeight) + 0.1);
            }
            if ((fSettings.ClipHeight > 0) && (bitmapHeight > fSettings.ClipHeight))
            {
                bitmapHeight = fSettings.ClipHeight;
            }

            // Stop here if the caller is only requesting the resulting bitmap's measurements.
            if (isRequestingBitmapInfoOnly)
            {
                var bitmapSettings = new WinRT.Interop.Graphics.BitmapSettings();
                bitmapSettings.PixelFormat = WinRT.Interop.Graphics.PixelFormat.Grayscale;
                bitmapSettings.PremultipliedAlphaApplied = true;
                bitmapSettings.PixelWidth  = bitmapWidth;
                bitmapSettings.PixelHeight = bitmapHeight;
                return(new TextBitmapDataResult(new WinRT.Interop.Graphics.BitmapInfo(bitmapSettings)));
            }

            // Determine if the text contains any visible/printable characters.
            bool hasPrintableCharacters = false;

            foreach (char nextCharacter in textBlock.Text.ToCharArray())
            {
                if ((System.Char.IsWhiteSpace(nextCharacter) == false) && (System.Char.IsControl(nextCharacter) == false))
                {
                    hasPrintableCharacters = true;
                    break;
                }
            }

            // If there is no text to render, then stop here and return an empty bitmap.
            // Note: This is a huge optimization. No point in rendering text below if you can't see the characters.
            if (hasPrintableCharacters == false)
            {
                var bitmapSettings = new WinRT.Interop.Graphics.BitmapSettings();
                bitmapSettings.PixelFormat = WinRT.Interop.Graphics.PixelFormat.Grayscale;
                bitmapSettings.PremultipliedAlphaApplied = true;
                bitmapSettings.PixelWidth  = bitmapWidth;
                bitmapSettings.PixelHeight = bitmapHeight;
                var emptyGrayscaleBitmap = new WinRT.Interop.Graphics.Bitmap();
                emptyGrayscaleBitmap.FormatUsing(new WinRT.Interop.Graphics.BitmapInfo(bitmapSettings));
                return(new TextBitmapDataResult(emptyGrayscaleBitmap));
            }

            // If the text has been clipped, then shift the text within the bounds of the bitmap.
            System.Windows.Media.TranslateTransform transform = null;
            if (textBlock.ActualWidth > (double)bitmapWidth)
            {
                transform = new System.Windows.Media.TranslateTransform();
                if (textBlock.TextAlignment == System.Windows.TextAlignment.Right)
                {
                    transform.X = bitmapWidth - textBlock.ActualWidth;
                }
                else if (textBlock.TextAlignment == System.Windows.TextAlignment.Center)
                {
                    transform.X = (bitmapWidth - textBlock.ActualWidth) / 2.0;
                }
            }

            // Render the text to a 32-bit color bitmap.
            System.Windows.Media.Imaging.WriteableBitmap writeableBitmap = null;
            try
            {
                // Create the bitmap.
                writeableBitmap = new System.Windows.Media.Imaging.WriteableBitmap(bitmapWidth, bitmapHeight);

                // Create a rectangle used to render a black background.
                var backgroundColor     = System.Windows.Media.Colors.Black;
                var backgroundRectangle = new System.Windows.Shapes.Rectangle();
                backgroundRectangle.Width  = bitmapWidth;
                backgroundRectangle.Height = bitmapHeight;
                backgroundRectangle.Fill   = new System.Windows.Media.SolidColorBrush(backgroundColor);

                // Convert the background color object to a 32-bit integer.
                // To be compared with the bitmap's integer pixel array below.
                int backgroundColorAsInt32 =
                    ((int)backgroundColor.B) |
                    ((int)backgroundColor.G << 8) |
                    ((int)backgroundColor.R << 16) |
                    ((int)backgroundColor.A << 24);

                // Attempt to render text to the bitmap.
                // Note: There is a bug on Windows Phone where WriteableBitmap sometimes fails to render/inavlidate
                //       content if a Xaml DrawingSurfaceBackgroundGrid is being used by the application.
                //       If this happens, then we must attempt to render again. There is no other known work-around.
                bool wasDrawn = false;
                for (int renderAttempt = 1; renderAttempt <= 3; renderAttempt++)
                {
                    // Notify the owner(s) that we're about to render to the bitmap.
                    if (this.Rendering != null)
                    {
                        this.Rendering.Invoke(this, new DotNetWriteableBitmapEventArgs(writeableBitmap));
                    }

                    // Render the text and its black background to the bitmap.
                    writeableBitmap.Render(backgroundRectangle, null);
                    writeableBitmap.Render(textBlock, transform);
                    writeableBitmap.Invalidate();

                    // --- Verify that the above text was successfully drawn to the bitmap. ---

                    // First, check that the black rectangle was drawn to the bitmap.
                    // This is a fast check because we only need to read one pixel in the bitmap's top-left corner.
                    if (writeableBitmap.Pixels[0] != backgroundColorAsInt32)
                    {
                        continue;
                    }

                    // Next, check that text was drawn to the bitmap.
                    if (hasPrintableCharacters)
                    {
                        // Traverse all pixels in the bitmap until we find 1 pixel that does not match the background color.
                        for (int pixelIndex = writeableBitmap.Pixels.Length - 1; pixelIndex >= 0; pixelIndex--)
                        {
                            if (writeableBitmap.Pixels[pixelIndex] != backgroundColorAsInt32)
                            {
                                wasDrawn = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        // The given text does not contain any visible characters. So, we're done.
                        wasDrawn = true;
                    }

                    // Stop now if we've successfully drawn to the bitmap.
                    if (wasDrawn)
                    {
                        break;
                    }
                }

                // Log a failure if we were unable to render text.
                // Note: This still returns a bitmap. Should we?
                if (wasDrawn == false)
                {
                    String message = "Failed to create a bitmap for text: \"" + textBlock.Text + "\"\r\n";
                    Corona.WinRT.Interop.Logging.LoggingServices.Log(message);
                }
            }
            catch (Exception ex)
            {
                return(new TextBitmapDataResult(ex.Message));
            }

            // Convert the 32-bit color bitmap to 8-bit grayscale.
            var rgbaBitmap     = DotNetBitmap.From(writeableBitmap);
            var bitmapConveter = new WinRT.Interop.Graphics.BitmapConverter();

            bitmapConveter.PixelFormat = WinRT.Interop.Graphics.PixelFormat.Grayscale;
            var grayscaleBitmap = bitmapConveter.CreateBitmapFrom(rgbaBitmap);

            rgbaBitmap.ReleaseByteBuffer();
            if (grayscaleBitmap == null)
            {
                return(new TextBitmapDataResult("Failed to convert the 32-bit color text to a grayscale bitmap."));
            }

            // Return the text as a grayscaled bitmap.
            return(new TextBitmapDataResult(grayscaleBitmap));
        }
        public addSystemApp()
        {
            InitializeComponent();
            Rectangle rect = new Rectangle();

            rect.Width  = 62;
            rect.Height = 62;
            rect.Fill   = new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"]);
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                int y = 0;
                foreach (string app in clsData.appTitles)
                {
                    try
                    {
                        System.Windows.Media.Imaging.WriteableBitmap wb = new System.Windows.Media.Imaging.WriteableBitmap(52, 52);
                        StackPanel panel = new StackPanel();

                        panel.Orientation = System.Windows.Controls.Orientation.Horizontal;

                        wb.Render(rect, null);

                        Image img = new Image();

                        img.Margin = new Thickness(1, 1, 10, 1);
                        img.Width  = 52;
                        img.Height = 52;
                        System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                        using (var file = store.OpenFile(app + ".jpg", FileMode.Open, FileAccess.Read))
                        {
                            bmp.SetSource(file);
                        }

                        img.Source = bmp;
                        wb.Render(img, null);
                        wb.Invalidate();
                        img.Source            = wb;
                        img.VerticalAlignment = System.Windows.VerticalAlignment.Center;

                        TextBlock text = new TextBlock();
                        text.Text              = app;
                        text.FontSize          = 30;
                        text.FontWeight        = FontWeights.Light;
                        text.VerticalAlignment = System.Windows.VerticalAlignment.Center;

                        panel.Name   = "panel_" + y;
                        panel.Tap   += new EventHandler <GestureEventArgs>(panel_Tap);
                        panel.Margin = new Thickness(0, 1, 1, 10);

                        panel.Children.Add(img);
                        panel.Children.Add(text);

                        stackPanel1.Children.Add(panel);
                        y += 1;
                    }
                    catch (Exception ez)
                    {
                        MessageBox.Show(ez.Message + " " + ez.StackTrace);
                    }
                }
            }
        }
Beispiel #7
0
        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            uint retval = Microsoft.Phone.InteropServices.ComBridge.RegisterComDll("libwph.dll", new Guid("56624E8C-CF91-41DF-9C31-E25A98FAF464"));

            libwph = (Imangodll) new Cmangodll();
            string str = "";

            Rectangle rect = new Rectangle();

            rect.Width  = 62;
            rect.Height = 62;
            rect.Fill   = new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"]);

            var stream = System.Windows.Application.GetResourceStream(new Uri("menu.folder", UriKind.Relative));

            curMenu = new menu();
            try
            {
                var serial = new XmlSerializer(typeof(menu));
                curMenu = (menu)serial.Deserialize(stream.Stream);
            }
            catch
            {
            }



            int y = 0;

            foreach (appentry app in curMenu.apps)
            {
                StackPanel panel = new StackPanel();



                panel.Orientation = System.Windows.Controls.Orientation.Horizontal;
                System.Windows.Media.Imaging.WriteableBitmap wb = new System.Windows.Media.Imaging.WriteableBitmap(62, 62);

                wb.Render(rect, null);

                Image img = new Image();

                img.Margin = new Thickness(1, 1, 10, 1);
                img.Width  = 62;
                img.Height = 62;

                /*System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                 * using (var file = store.OpenFile(app.guid + ".jpg", FileMode.Open, FileAccess.Read))
                 * {
                 *  bmp.SetSource(file);
                 *  //img.Source = Microsoft.Phone.PictureDecoder.DecodeJpeg(file);
                 * }*/
                System.Diagnostics.Debug.WriteLine(app.guid);
                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(new Uri("/apps/" + app.guid + ".jpg", UriKind.Relative));
                bmp.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.None;
                img.Source        = bmp;
                wb.Render(img, null);
                wb.Invalidate();
                img.Source            = wb;
                img.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                panel.Children.Add(img);
                TextBlock text = new TextBlock();
                text.Text              = app.name;
                text.FontSize          = 31;
                text.FontWeight        = FontWeights.Light;
                text.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                panel.Children.Add(text);

                panel.Name   = "panel_" + y;
                panel.Margin = new Thickness(1, 1, 1, 10);

                ListBoxItem foo = new ListBoxItem();
                foo.Content = panel;
                foo.Tap    += new EventHandler <GestureEventArgs>(panel_Tap);
                foo.Name    = "danel_" + y;


                stackPanel1.Children.Add(foo);
                y += 1;
                wb = null;
            }

            PageTitle.Text        = curMenu.name;
            PageTitle.Opacity     = op;
            scrollViewer1.Opacity = op;
            scrollViewer1.Margin  = new Thickness(46, top, 0, 0);



            tim          = new System.Windows.Threading.DispatcherTimer();
            tim.Interval = new TimeSpan(0, 0, 0, 0, 10);
            tim.Tick    += new EventHandler(tim_Tick);
            tim.Start();
        }
Beispiel #8
0
        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            string str = "";

            if (NavigationContext.QueryString.TryGetValue("tile", out str))
            {
                Rectangle rect = new Rectangle();
                rect.Width  = 62;
                rect.Height = 62;
                rect.Fill   = new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"]);

                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (var stream = new IsolatedStorageFileStream(str + ".folder", FileMode.OpenOrCreate, store))
                    {
                        using (var reader = new StreamReader(stream))
                        {
                            curMenu = new menu();
                            try
                            {
                                var serial = new XmlSerializer(typeof(menu));
                                curMenu = (menu)serial.Deserialize(stream);
                            }
                            catch
                            {
                            }
                        }
                    }


                    int y = 0;

                    foreach (appentry app in curMenu.apps)
                    {
                        StackPanel panel = new StackPanel();

                        panel.Orientation = System.Windows.Controls.Orientation.Horizontal;
                        System.Windows.Media.Imaging.WriteableBitmap wb = new System.Windows.Media.Imaging.WriteableBitmap(62, 62);

                        wb.Render(rect, null);

                        Image img = new Image();

                        img.Margin = new Thickness(1, 1, 10, 1);
                        img.Width  = 62;
                        img.Height = 62;
                        System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                        using (var file = store.OpenFile(app.guid + ".jpg", FileMode.Open, FileAccess.Read))
                        {
                            bmp.SetSource(file);
                        }

                        img.Source = bmp;
                        wb.Render(img, null);
                        wb.Invalidate();
                        img.Source            = wb;
                        img.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                        panel.Children.Add(img);
                        TextBlock text = new TextBlock();
                        text.Text              = app.name;
                        text.FontSize          = 31;
                        text.FontWeight        = FontWeights.Light;
                        text.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                        panel.Children.Add(text);

                        panel.Name   = "panel_" + y;
                        panel.Margin = new Thickness(1, 1, 1, 10);



                        ListBoxItem foo = new ListBoxItem();
                        foo.Content = panel;
                        foo.Tap    += new EventHandler <GestureEventArgs>(panel_Tap);
                        foo.Name    = "danel_" + y;


                        stackPanel1.Children.Add(foo);
                        y += 1;
                        wb = null;
                    }

                    PageTitle.Text        = curMenu.name;
                    PageTitle.Opacity     = op;
                    scrollViewer1.Opacity = op;
                    scrollViewer1.Margin  = new Thickness(46, top, 0, 0);
                }
            }
            else
            {
                //Not a folder. Go to the editor
                NavigationService.Navigate(new Uri("/MainPage.xaml?init=true", UriKind.Relative));
            }
            tim          = new System.Windows.Threading.DispatcherTimer();
            tim.Interval = new TimeSpan(0, 0, 0, 0, 10);
            tim.Tick    += new EventHandler(tim_Tick);
            tim.Start();
        }
Beispiel #9
0
        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            NavigationContext.QueryString.TryGetValue("folder", out folderName);
            if (folderName != "")
            {
                PageTitle.Text = "edit: " + folderName;
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (var stream = new IsolatedStorageFileStream(folderName + ".folder", FileMode.OpenOrCreate, store))
                    {
                        using (var reader = new StreamReader(stream))
                        {
                            curMenu = new menu();
                            try
                            {
                                var serial = new XmlSerializer(typeof(menu));
                                curMenu = (menu)serial.Deserialize(stream);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                if (curMenu.apps == null)
                {
                    curMenu.apps = new System.Collections.ObjectModel.Collection <appentry>();
                }
            }
            else
            {
                MessageBox.Show("I didn't get any arguments...", "Well this is awkward", MessageBoxButton.OK);
            }

            Rectangle rect = new Rectangle();

            rect.Width  = 62;
            rect.Height = 62;
            rect.Fill   = new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"]);


            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                int y = 0;

                foreach (appentry app in clsData.installedApps)
                {
                    try
                    {
                        System.Windows.Media.Imaging.WriteableBitmap wb = new System.Windows.Media.Imaging.WriteableBitmap(52, 52);
                        StackPanel panel = new StackPanel();

                        panel.Orientation = System.Windows.Controls.Orientation.Horizontal;

                        wb.Render(rect, null);

                        Image img = new Image();

                        img.Margin = new Thickness(1, 1, 10, 1);
                        img.Width  = 52;
                        img.Height = 52;
                        System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                        using (var file = store.OpenFile(app.guid + ".jpg", FileMode.Open, FileAccess.Read))
                        {
                            bmp.SetSource(file);
                        }
                        System.Diagnostics.Debug.WriteLine("apps/" + app.guid + ".jpg");
                        //bmp.SetSource(Application.GetResourceStream(new Uri("apps/" + app.guid + ".jpg", UriKind.Relative)).Stream);
                        //System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(new Uri("/" + app.image, UriKind.Relative));
                        img.Source = bmp;
                        wb.Render(img, null);
                        wb.Invalidate();
                        img.Source            = wb;
                        img.VerticalAlignment = System.Windows.VerticalAlignment.Center;

                        TextBlock text = new TextBlock();
                        text.Text              = app.name;
                        text.FontSize          = 30;
                        text.FontWeight        = FontWeights.Light;
                        text.VerticalAlignment = System.Windows.VerticalAlignment.Center;

                        CheckBox cb = new CheckBox();
                        cb.Name = "app_" + app.guid;

                        foreach (appentry folderapp in curMenu.apps)
                        {
                            if (folderapp.guid == app.guid)
                            {
                                cb.IsChecked = true;
                            }
                        }

                        cb.Checked   += new RoutedEventHandler(cb_Checked);
                        cb.Unchecked += new RoutedEventHandler(cb_Unchecked);

                        selectedApps.Add(cb);

                        //panel.Name = app.guid;
                        panel.Name = "panel_" + y;
                        //panel.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(panel_Tap);
                        panel.Margin = new Thickness(0, 1, 1, 10);

                        panel.Children.Add(cb);
                        panel.Children.Add(img);
                        panel.Children.Add(text);

                        stackPanel1.Children.Add(panel);
                        y += 1;
                        //wb = null;
                    }
                    catch (Exception ez)
                    {
                        //MessageBox.Show(ez.Message + " " + ez.StackTrace);
                    }
                }
            }
        }