示例#1
0
        public void When_Horizontal_And_Three_With_Spacing()
        {
            var SUT = new StackPanel()
            {
                Name = "test", Orientation = Orientation.Horizontal, Spacing = 5
            };

            var c1 = SUT.AddChild(
                new View {
                Name = "Child01", RequestedDesiredSize = new Windows.Foundation.Size(5, 8)
            }
                );

            var c2 = SUT.AddChild(
                new View {
                Name = "Child02", RequestedDesiredSize = new Windows.Foundation.Size(12, 7)
            }
                );

            var c3 = SUT.AddChild(
                new View {
                Name = "Child02", RequestedDesiredSize = new Windows.Foundation.Size(12, 5)
            }
                );

            SUT.Measure(new Windows.Foundation.Size(20, 20));
            var measuredSize = SUT.DesiredSize;

            Assert.AreEqual(new Windows.Foundation.Size(39, 8), measuredSize, "measuredSize");

            Assert.AreEqual(new Windows.Foundation.Size(5, 8), c1.RequestedDesiredSize);
            Assert.AreEqual(new Windows.Foundation.Size(12, 7), c2.RequestedDesiredSize);
            Assert.AreEqual(new Windows.Foundation.Size(12, 5), c3.RequestedDesiredSize);

            SUT.Arrange(new Windows.Foundation.Rect(0, 0, 20, 20));
            Assert.AreEqual(new Windows.Foundation.Rect(0, 0, 5, 20), c1.Arranged);
            Assert.AreEqual(new Windows.Foundation.Rect(10, 0, 12, 20), c2.Arranged);
            Assert.AreEqual(new Windows.Foundation.Rect(27, 0, 12, 20), c3.Arranged);

            Assert.AreEqual(3, SUT.GetChildren().Count());
        }
示例#2
0
        public FixedDocument GetDocument(Size pageSize, TeamBewerb tournament, bool printTeamName, bool concatRounds)
        {
            document = new FixedDocument();
            document.DocumentPaginator.PageSize = pageSize;

            var teamPanels = new List <StackPanel>();

            foreach (var team in tournament.Teams.Where(v => !v.IsVirtual)
                     .OrderBy(t => t.StartNumber))                             //Für jedes Team eine Spiegel-Karte
            {
                if (concatRounds)
                {
                    teamPanels.Add(GetTeamPanel(team, printTeamName, tournament.Is8TurnsGame));
                }
                else
                {
                    teamPanels.AddRange(GetTeamPanels(team, printTeamName, tournament.Is8TurnsGame));
                }
            }

            var pagePanel = new StackPanel();

            foreach (var teamPanel in teamPanels)
            {
                pagePanel.Children.Add(teamPanel);
                pagePanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                pagePanel.Arrange(new Rect(0, 0, pagePanel.DesiredSize.Width, pagePanel.DesiredSize.Height));

                if (pagePanel.ActualHeight + teamPanel.ActualHeight > document.DocumentPaginator.PageSize.Height)
                {
                    SetPagePanelToDocument(pagePanel);
                    pagePanel = new StackPanel();
                }
            }
            if (pagePanel.Children.Count > 0)
            {
                SetPagePanelToDocument(pagePanel);
            }

            return(document);
        }
示例#3
0
        private void Print_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog dialog = new PrintDialog();

            if (dialog.ShowDialog() == true)
            {
                StackPanel panel = new StackPanel();
                panel.Margin = new Thickness(15);
                panel.Children.Add((Canvas)XamlReader.Parse(XamlWriter.Save(this.DrawingHost.DrawingControl)));
                TextBlock myBlock = new TextBlock();
                myBlock.Text          = "Drawing";
                myBlock.TextAlignment = TextAlignment.Center;
                panel.Children.Add(myBlock);

                panel.Measure(new Size(dialog.PrintableAreaWidth,
                                       dialog.PrintableAreaHeight));
                panel.Arrange(new Rect(new System.Windows.Point(0, 0), panel.DesiredSize));
                dialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
                dialog.PrintVisual(panel, "Drawing");
            }
        }
示例#4
0
        public void When_Horizontal_And_ArrangeIsBiggerThanMeasure()
        {
            var SUT = new StackPanel {
                Name = "test", Orientation = Orientation.Horizontal
            };

            var c1 = SUT.AddChild(
                child: new View {
                Name = "Child01", RequestedDesiredSize = new Size(width: 10, height: 10)
            }
                );

            SUT.Measure(availableSize: new Size(width: 20, height: 20));
            var measuredSize = SUT.DesiredSize;

            Assert.AreEqual(expected: new Size(width: 10, height: 10), actual: measuredSize, message: "measuredSize");

            SUT.Arrange(finalRect: new Rect(x: 0, y: 0, width: 20, height: 20));
            Assert.AreEqual(expected: new Rect(x: 0, y: 0, width: 10, height: 20), actual: c1.Arranged);

            Assert.AreEqual(expected: 1, actual: SUT.GetChildren().Count());
        }
示例#5
0
        public void When_Horizontal_And_Three_With_Spacing()
        {
            var SUT = new StackPanel {
                Name = "test", Orientation = Orientation.Horizontal, Spacing = 5
            };

            var c1 = SUT
                     .AddChild(
                child: new View {
                Name = "Child01", RequestedDesiredSize = new Size(width: 5, height: 8)
            }
                );

            var c2 = SUT
                     .AddChild(
                child: new View {
                Name = "Child02", RequestedDesiredSize = new Size(width: 12, height: 7)
            }
                );

            var c3 = SUT
                     .AddChild(
                child: new View {
                Name = "Child02", RequestedDesiredSize = new Size(width: 12, height: 5)
            }
                );

            SUT.Measure(availableSize: new Size(width: 20, height: 20));
            SUT.DesiredSize.Should().Be(new Size(20, 8));
            SUT.UnclippedDesiredSize.Should().Be(new Size(39, 8));

            SUT.Arrange(finalRect: new Rect(x: 0, y: 0, width: 20, height: 20));
            Assert.AreEqual(expected: new Rect(x: 0, y: 0, width: 5, height: 20), actual: c1.Arranged);
            Assert.AreEqual(expected: new Rect(x: 10, y: 0, width: 12, height: 20), actual: c2.Arranged);
            Assert.AreEqual(expected: new Rect(x: 27, y: 0, width: 12, height: 20), actual: c3.Arranged);

            Assert.AreEqual(expected: 3, actual: SUT.GetChildren().Count());
        }
示例#6
0
        public void Measuring_Invisible_Control_Should_Not_Invalidate_Parent_Measure()
        {
            Border child;
            var    target = new StackPanel
            {
                Children =
                {
                    (child    = new Border
                    {
                        Width = 100,
                    }),
                }
            };

            target.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            target.Arrange(new Rect(target.DesiredSize));

            Assert.True(target.IsMeasureValid);
            Assert.True(target.IsArrangeValid);
            Assert.Equal(new Size(100, 0), child.DesiredSize);

            child.IsVisible = false;
            Assert.Equal(default, child.DesiredSize);
示例#7
0
        public void When_Horizontal_And_ArrangeIsBiggerThanMeasure()
        {
            var SUT = new StackPanel()
            {
                Name = "test", Orientation = Orientation.Horizontal
            };

            var c1 = SUT.AddChild(
                new View {
                Name = "Child01", RequestedDesiredSize = new Windows.Foundation.Size(10, 10)
            }
                );

            SUT.Measure(new Windows.Foundation.Size(20, 20));
            var measuredSize = SUT.DesiredSize;

            Assert.AreEqual(new Windows.Foundation.Size(10, 10), measuredSize, "measuredSize");

            SUT.Arrange(new Windows.Foundation.Rect(0, 0, 20, 20));
            Assert.AreEqual(new Windows.Foundation.Rect(0, 0, 10, 20), c1.Arranged);

            Assert.AreEqual(1, SUT.GetChildren().Count());
        }
示例#8
0
        public void When_Vertical_And_Fixed_Height_Item_With_Margin()
        {
            var SUT = new StackPanel {
                Name = "test", Orientation = Orientation.Vertical
            };

            var c1 = SUT.AddChild(
                child: new View
            {
                Name = "Child01",
                RequestedDesiredSize = new Size(width: 10, height: 10),
            }
                );


            var c2 = SUT.AddChild(
                child: new View
            {
                Name   = "Child02",
                Height = 10,
                Margin = new Thickness(uniformLength: 10)
            }
                );

            SUT.Measure(availableSize: new Size(width: 40, height: float.PositiveInfinity));
            SUT.DesiredSize.Should().Be(new Size(20, 40));
            c1.DesiredSize.Should().Be(new Size(10, 10));
            c2.DesiredSize.Should().Be(new Size(20, 30));

            SUT.Arrange(finalRect: new Rect(x: 0, y: 0, width: 30, height: 40));
            SUT.Arranged.Should().Be((Rect)"0,0,30,40");
            c1.Arranged.Should().Be((Rect)"0,0,30,10");
            c2.Arranged.Should().Be((Rect)"10,20,10,10");

            SUT.GetChildren().Should().HaveCount(2);
        }
示例#9
0
        public void StackPanelMarginTest()
        {
            StackPanel panel = new StackPanel {
                Orientation = Orientation.Horizontal
            };

            FrameworkElement child1 = new FrameworkElement {
                Width = 80, Margin = new Thickness(10)
            };
            FrameworkElement child2 = new FrameworkElement {
                Width = 60, Margin = new Thickness(20)
            };
            FrameworkElement child3 = new FrameworkElement {
                Width = 40, Margin = new Thickness(30)
            };

            panel.Children.Add(child1);
            panel.Children.Add(child2);
            panel.Children.Add(child3);

            panel.Measure(new Size(1000, 1000));

            Assert.AreEqual(new Size(300, 60), panel.DesiredSize);

            panel.Arrange(new Rect(300, 1000));

            Assert.AreEqual(new Size(300, 1000), panel.VisualSize);

            Assert.AreEqual(new Size(80, 980), child1.VisualSize);
            Assert.AreEqual(new Size(60, 960), child2.VisualSize);
            Assert.AreEqual(new Size(40, 940), child3.VisualSize);

            Assert.AreEqual(new Point(10, 10), child1.VisualOffset);
            Assert.AreEqual(new Point(120, 20), child2.VisualOffset);
            Assert.AreEqual(new Point(230, 30), child3.VisualOffset);
        }
示例#10
0
        public FixedDocument GetDocument(Size pageSize, TeamBewerb tournament)
        {
            document = new FixedDocument();
            document.DocumentPaginator.PageSize = pageSize;

            var allGames = tournament.GetAllGames().Where(g => g.IsNotPauseGame && g.CourtNumber > 0);

            var bahnblöcke = new List <StackPanel>();

            foreach (var game in allGames.OrderBy(b => b.CourtNumber).ThenBy(r => r.RoundOfGame).ThenBy(g => g.GameNumber))
            {
                bahnblöcke.Add(GetNewBahnblock(game, tournament.Is8TurnsGame));
            }

            var pagePanel = new StackPanel();

            foreach (var bahnblock in bahnblöcke)
            {
                pagePanel.Children.Add(bahnblock);
                pagePanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                pagePanel.Arrange(new Rect(0, 0, pagePanel.DesiredSize.Width, pagePanel.DesiredSize.Height));

                if (pagePanel.ActualHeight + bahnblock.ActualHeight > document.DocumentPaginator.PageSize.Height)
                {
                    SetPagePanelToDocument(pagePanel);
                    pagePanel = new StackPanel();
                }
            }

            if (pagePanel.Children.Count > 0)
            {
                SetPagePanelToDocument(pagePanel);
            }

            return(document);
        }
示例#11
0
        public void Only_Arrange_Visible_Children(Orientation orientation)
        {
            var hiddenPanel = new Panel {
                Width = 10, Height = 10, IsVisible = false
            };
            var panel = new Panel {
                Width = 10, Height = 10
            };

            var target = new StackPanel
            {
                Spacing     = 40,
                Orientation = orientation,
                Children    =
                {
                    hiddenPanel,
                    panel
                }
            };

            target.Measure(Size.Infinity);
            target.Arrange(new Rect(target.DesiredSize));
            Assert.Equal(new Rect(0, 0, 10, 10), panel.Bounds);
        }
示例#12
0
        /// <summary>
        /// Mitä tapahtuu kun klikkaa Tulosta pelitulos -menuitemiä.
        /// Tulostetaan pelaajien nimet, tehdyt siirrot ja kuva pelilaudasta
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Tulosta_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.PrintDialog dialogi = new System.Windows.Controls.PrintDialog();
            if (dialogi.ShowDialog() != true)
            {
                return;
            }

            String[] erottimet = new String[] { " " };
            String   p1        = textBox1.Text;
            String   p2        = textBox2.Text;

            string[] sanat  = p1.Split(erottimet, StringSplitOptions.RemoveEmptyEntries);
            string[] sanat2 = p2.Split(erottimet, StringSplitOptions.RemoveEmptyEntries);
            if (sanat.Length == 0)
            {
                p1 = "YläPelaaja";
            }
            if (sanat2.Length == 0)
            {
                p2 = "AlaPelaaja";
            }

            StackPanel tulostus = new StackPanel();

            tulostus.Margin = new Thickness(50);

            TextBlock omaBlock = new TextBlock();

            StringBuilder teksti = new StringBuilder();

            teksti.Append(muistutus + "\r\n" + p1 + " " + p2 + "\r\n");
            List <String> lista = new List <String>();

            int pixelWidth  = 0;
            int pixelHeight = 0;

            if (onkoBreakthrough == 0)
            {
                lista       = KokoaSiirrot(pelialue.Mustat_siirrot, pelialue.Valkoiset_siirrot);
                pixelWidth  = (int)pelialue.ActualWidth;
                pixelHeight = (int)pelialue.ActualHeight;
            }
            else
            {
                lista       = KokoaSiirrot(tammialue.Valkoiset_siirrot, tammialue.Punaiset_siirrot);
                pixelWidth  = (int)tammialue.ActualWidth;
                pixelHeight = (int)tammialue.ActualHeight;
            }

            foreach (String alkio in lista)
            {
                teksti.Append(alkio + "\r\n");
            }

            omaBlock.Text = teksti.ToString();
            tulostus.Children.Add(omaBlock);

            // luodaan rendertragetbitmap, joka lisätään kuvan sourceksi
            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(pixelWidth, pixelHeight,
                                                                           96, 96, PixelFormats.Pbgra32);

            if (onkoBreakthrough == 0)
            {
                renderTargetBitmap.Render(pelialue);
            }
            else
            {
                renderTargetBitmap.Render(tammialue);
            }
            Image kuva = new Image();

            kuva.Source = renderTargetBitmap;

            tulostus.Children.Add(kuva);

            tulostus.Measure(new Size(dialogi.PrintableAreaWidth, dialogi.PrintableAreaHeight));
            tulostus.Arrange(new Rect(new Point(0, 0), tulostus.DesiredSize));

            dialogi.PrintVisual(tulostus, "Tulokset");
        }
示例#13
0
        public void Arranges_Horizontal_Children_With_Correct_Bounds()
        {
            var target = new StackPanel
            {
                Orientation = Orientation.Horizontal,
                Children    =
                {
                    new TestControl
                    {
                        VerticalAlignment = VerticalAlignment.Top,
                        MeasureSize       = new Size(10, 50),
                    },
                    new TestControl
                    {
                        VerticalAlignment = VerticalAlignment.Top,
                        MeasureSize       = new Size(10, 150),
                    },
                    new TestControl
                    {
                        VerticalAlignment = VerticalAlignment.Center,
                        MeasureSize       = new Size(10, 50),
                    },
                    new TestControl
                    {
                        VerticalAlignment = VerticalAlignment.Center,
                        MeasureSize       = new Size(10, 150),
                    },
                    new TestControl
                    {
                        VerticalAlignment = VerticalAlignment.Bottom,
                        MeasureSize       = new Size(10, 50),
                    },
                    new TestControl
                    {
                        VerticalAlignment = VerticalAlignment.Bottom,
                        MeasureSize       = new Size(10, 150),
                    },
                    new TestControl
                    {
                        VerticalAlignment = VerticalAlignment.Stretch,
                        MeasureSize       = new Size(10, 50),
                    },
                    new TestControl
                    {
                        VerticalAlignment = VerticalAlignment.Stretch,
                        MeasureSize       = new Size(10, 150),
                    },
                }
            };

            target.Measure(new Size(150, 100));
            Assert.Equal(new Size(80, 100), target.DesiredSize);

            target.Arrange(new Rect(target.DesiredSize));

            var bounds = target.Children.Select(x => x.Bounds).ToArray();

            Assert.Equal(
                new[]
            {
                new Rect(0, 0, 10, 50),
                new Rect(10, 0, 10, 100),
                new Rect(20, 25, 10, 50),
                new Rect(30, 0, 10, 100),
                new Rect(40, 50, 10, 50),
                new Rect(50, 0, 10, 100),
                new Rect(60, 0, 10, 100),
                new Rect(70, 0, 10, 100),
            }, bounds);
        }
示例#14
0
        public void Arranges_Vertical_Children_With_Correct_Bounds()
        {
            var target = new StackPanel
            {
                Orientation = Orientation.Vertical,
                Children    =
                {
                    new TestControl
                    {
                        HorizontalAlignment = HorizontalAlignment.Left,
                        MeasureSize         = new Size(50, 10),
                    },
                    new TestControl
                    {
                        HorizontalAlignment = HorizontalAlignment.Left,
                        MeasureSize         = new Size(150, 10),
                    },
                    new TestControl
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        MeasureSize         = new Size(50, 10),
                    },
                    new TestControl
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        MeasureSize         = new Size(150, 10),
                    },
                    new TestControl
                    {
                        HorizontalAlignment = HorizontalAlignment.Right,
                        MeasureSize         = new Size(50, 10),
                    },
                    new TestControl
                    {
                        HorizontalAlignment = HorizontalAlignment.Right,
                        MeasureSize         = new Size(150, 10),
                    },
                    new TestControl
                    {
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                        MeasureSize         = new Size(50, 10),
                    },
                    new TestControl
                    {
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                        MeasureSize         = new Size(150, 10),
                    },
                }
            };

            target.Measure(new Size(100, 150));
            Assert.Equal(new Size(100, 80), target.DesiredSize);

            target.Arrange(new Rect(target.DesiredSize));

            var bounds = target.Children.Select(x => x.Bounds).ToArray();

            Assert.Equal(
                new[]
            {
                new Rect(0, 0, 50, 10),
                new Rect(0, 10, 100, 10),
                new Rect(25, 20, 50, 10),
                new Rect(0, 30, 100, 10),
                new Rect(50, 40, 50, 10),
                new Rect(0, 50, 100, 10),
                new Rect(0, 60, 100, 10),
                new Rect(0, 70, 100, 10),
            }, bounds);
        }
示例#15
0
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        /// <param name="task">
        /// The invoked task
        /// </param>
        /// <remarks>
        /// This method is called when a periodic or resource intensive task is invoked
        /// </remarks>
        protected override void OnInvoke(ScheduledTask task)
        {
            if (!LockScreenManager.IsProvidedByCurrentApplication)
            {
                try
                {
                    ScheduledActionService.Remove(task.Name);
                }
                catch (Exception)
                {
                }
                return;
            }

            var evnt = new ManualResetEvent(false);

            WebClient client = new WebClient();

            client.OpenReadCompleted += new OpenReadCompletedEventHandler((sender, e) =>
            {
                if (e.Error != null || e.Cancelled)
                {
                    evnt.Set();
                    return;
                }

                Deployment.Current.Dispatcher.BeginInvoke(async() =>
                {
                    string imageName = "";
                    if (LockScreen.GetImageUri().ToString().EndsWith("_A.jpg"))
                    {
                        imageName = "lockscreen_B.jpg";
                    }
                    else
                    {
                        imageName = "lockscreen_A.jpg";
                    }

                    using (var memoryStream = new MemoryStream())
                    {
                        try
                        {
                            e.Result.CopyTo(memoryStream);
                        }
                        catch (Exception)
                        {
                            e.Result.Close();
                            evnt.Set();
                            return;
                        }

                        memoryStream.Position = 0;

                        e.Result.Close();

                        PhotoModel model = new PhotoModel()
                        {
                            Buffer = memoryStream.GetWindowsRuntimeBuffer()
                        };

                        WriteableBitmap photo = new WriteableBitmap((int)model.Width, (int)model.Height);
                        await model.RenderBitmapAsync(photo);

                        // loading image
                        using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
                        {
                            if (iso.FileExists(imageName))
                            {
                                iso.DeleteFile(imageName);
                            }

                            var names = iso.GetFileNames("*_sthumb.jpg");
                            if (names.Length > 0)
                            {
                                int index1 = DateTime.Now.Millisecond % names.Length;
                                int index2 = (index1 + 1) % names.Length;
                                int index3 = (index2 + 1) % names.Length;
                                int index4 = (index3 + 1) % names.Length;

                                BitmapImage overlayBitmap1 = new BitmapImage();
                                BitmapImage overlayBitmap2 = new BitmapImage();
                                BitmapImage overlayBitmap3 = new BitmapImage();
                                BitmapImage overlayBitmap4 = new BitmapImage();

                                using (var stream = iso.OpenFile(names[index1], System.IO.FileMode.Open, System.IO.FileAccess.Read))
                                {
                                    overlayBitmap1.SetSource(stream);
                                }

                                using (var stream = iso.OpenFile(names[index2], System.IO.FileMode.Open, System.IO.FileAccess.Read))
                                {
                                    overlayBitmap2.SetSource(stream);
                                }

                                using (var stream = iso.OpenFile(names[index3], System.IO.FileMode.Open, System.IO.FileAccess.Read))
                                {
                                    overlayBitmap3.SetSource(stream);
                                }

                                using (var stream = iso.OpenFile(names[index4], System.IO.FileMode.Open, System.IO.FileAccess.Read))
                                {
                                    overlayBitmap4.SetSource(stream);
                                }

                                StackPanel container = new StackPanel()
                                {
                                    Width      = 480,
                                    Height     = 800,
                                    Background = new ImageBrush()
                                    {
                                        ImageSource = photo
                                    },
                                };

                                var imageContainer = new Canvas()
                                {
                                    Width               = 480,
                                    Height              = 800,
                                    VerticalAlignment   = VerticalAlignment.Top,
                                    HorizontalAlignment = HorizontalAlignment.Center,
                                    Background          = new SolidColorBrush(Colors.Transparent)
                                };

                                var initialMarginTop     = 32;
                                var additionalMarginTop  = 10;
                                var opacityBorderLength1 = 80;

                                var opacityBorder1 = new Border()
                                {
                                    Width      = opacityBorderLength1 + Constant.ThumbnailSmallSide / 2,
                                    Height     = Constant.ThumbnailSmallSide,
                                    Margin     = new Thickness(0, initialMarginTop, 0, 0),
                                    Background = new SolidColorBrush(Colors.Black),
                                    Opacity    = 0.6
                                };
                                Ellipse overlayImage1 = new Ellipse()
                                {
                                    Width  = Constant.ThumbnailSmallSide,
                                    Height = Constant.ThumbnailSmallSide,
                                    Fill   = new ImageBrush()
                                    {
                                        ImageSource = overlayBitmap1
                                    },
                                    Margin = new Thickness(opacityBorderLength1, initialMarginTop, 0, 0)
                                };

                                var opacityBorderLength2 = opacityBorderLength1 + Constant.ThumbnailSmallSide;
                                var opacityBorder2       = new Border()
                                {
                                    Width      = opacityBorderLength2 + Constant.ThumbnailSmallSide / 2,
                                    Height     = Constant.ThumbnailSmallSide,
                                    Margin     = new Thickness(0, initialMarginTop + additionalMarginTop + Constant.ThumbnailSmallSide, 0, 0),
                                    Background = new SolidColorBrush(Colors.Black),
                                    Opacity    = 0.6
                                };
                                Ellipse overlayImage2 = new Ellipse()
                                {
                                    Width  = Constant.ThumbnailSmallSide,
                                    Height = Constant.ThumbnailSmallSide,
                                    Fill   = new ImageBrush()
                                    {
                                        ImageSource = overlayBitmap2
                                    },
                                    Margin = new Thickness(opacityBorderLength2, initialMarginTop + additionalMarginTop + Constant.ThumbnailSmallSide, 0, 0)
                                };

                                var opacityBorderLength3 = opacityBorderLength1 + 2 * Constant.ThumbnailSmallSide;
                                var opacityBorder3       = new Border()
                                {
                                    Width      = opacityBorderLength3 + Constant.ThumbnailSmallSide / 2,
                                    Height     = Constant.ThumbnailSmallSide,
                                    Margin     = new Thickness(0, initialMarginTop + 2 * additionalMarginTop + 2 * Constant.ThumbnailSmallSide, 0, 0),
                                    Background = new SolidColorBrush(Colors.Black),
                                    Opacity    = 0.6
                                };
                                Ellipse overlayImage3 = new Ellipse()
                                {
                                    Width  = Constant.ThumbnailSmallSide,
                                    Height = Constant.ThumbnailSmallSide,
                                    Fill   = new ImageBrush()
                                    {
                                        ImageSource = overlayBitmap3
                                    },
                                    Margin = new Thickness(opacityBorderLength3, initialMarginTop + 2 * additionalMarginTop + 2 * Constant.ThumbnailSmallSide, 0, 0)
                                };

                                var opacityBorderLength4 = opacityBorderLength1 + 3 * Constant.ThumbnailSmallSide;
                                var opacityBorder4       = new Border()
                                {
                                    Width      = opacityBorderLength4 + Constant.ThumbnailSmallSide / 2,
                                    Height     = Constant.ThumbnailSmallSide,
                                    Margin     = new Thickness(0, initialMarginTop + 3 * additionalMarginTop + 3 * Constant.ThumbnailSmallSide, 0, 0),
                                    Background = new SolidColorBrush(Colors.Black),
                                    Opacity    = 0.6
                                };
                                Ellipse overlayImage4 = new Ellipse()
                                {
                                    Width  = Constant.ThumbnailSmallSide,
                                    Height = Constant.ThumbnailSmallSide,
                                    Fill   = new ImageBrush()
                                    {
                                        ImageSource = overlayBitmap4
                                    },
                                    Margin = new Thickness(opacityBorderLength4, initialMarginTop + 3 * additionalMarginTop + 3 * Constant.ThumbnailSmallSide, 0, 0)
                                };

                                imageContainer.Children.Add(opacityBorder1);
                                imageContainer.Children.Add(overlayImage1);

                                imageContainer.Children.Add(opacityBorder2);
                                imageContainer.Children.Add(overlayImage2);

                                imageContainer.Children.Add(opacityBorder3);
                                imageContainer.Children.Add(overlayImage3);

                                imageContainer.Children.Add(opacityBorder4);
                                imageContainer.Children.Add(overlayImage4);

                                container.Children.Add(imageContainer);

                                //TextBlock headerTxtBlock = new TextBlock()
                                //{
                                //    FontFamily = new FontFamily("Comic Sans MS"),
                                //    Foreground = new SolidColorBrush(Colors.White),
                                //    FontSize = 40,
                                //    Text = "Amazing Daily Photo",
                                //    HorizontalAlignment = HorizontalAlignment.Center,
                                //    TextWrapping = TextWrapping.Wrap,
                                //    Margin = new Thickness(0, 10, 0, 0)
                                //};
                                //container.Children.Add(headerTxtBlock);

                                container.Measure(new Size(480, 800));
                                container.Arrange(new Rect(0, 0, 480, 800));

                                photo.Render(container, null);
                                photo.Invalidate();
                            }

                            IsolatedStorageFileStream isostream = iso.CreateFile(imageName);
                            Extensions.SaveJpeg(photo, isostream, photo.PixelWidth, photo.PixelHeight, 0, 100);
                            isostream.Close();
                        }
                    }

                    ChangeLockscreen(imageName, false);

                    evnt.Set();
                });
            });
            client.OpenReadAsync(new Uri(bingImageUri, UriKind.Absolute));

            evnt.WaitOne(15000);

#if DEBUG_AGENT
            ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(15));
#endif
            NotifyComplete();
        }
示例#16
0
        //private void dgPurchase_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        //{
        //    item = (sender as ListViewItem);
        //  //  btn_remove.IsEnabled = true;
        //   // btn_remove.Background = (Brush)color.ConvertFrom("#eb5151");
        //}

        //public static FixedDocument GetFixedDocument(FrameworkElement toPrint, PrintDialog printDialog)
        //{
        //    PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
        //    Size pageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
        //    Size visibleSize = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
        //    FixedDocument fixedDoc = new FixedDocument();
        //    //If the toPrint visual is not displayed on screen we neeed to measure and arrange it
        //    toPrint.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
        //    toPrint.Arrange(new Rect(new Point(0, 0), toPrint.DesiredSize));
        //    //
        //    Size size = toPrint.DesiredSize;
        //    //Will assume for simplicity the control fits horizontally on the page
        //    double yOffset = 0;
        //    while (yOffset < size.Height)
        //    {
        //        VisualBrush vb = new VisualBrush(toPrint);
        //        vb.Stretch = Stretch.None;
        //        vb.AlignmentX = AlignmentX.Left;
        //        vb.AlignmentY = AlignmentY.Top;
        //        vb.ViewboxUnits = BrushMappingMode.Absolute;
        //        vb.TileMode = TileMode.None;
        //        vb.Viewbox = new Rect(0, yOffset, visibleSize.Width, visibleSize.Height);
        //        PageContent pageContent = new PageContent();
        //        FixedPage page = new FixedPage();
        //        ((IAddChild)pageContent).AddChild(page);
        //        fixedDoc.Pages.Add(pageContent);
        //        page.Width = pageSize.Width;
        //        page.Height = pageSize.Height;
        //        Canvas canvas = new Canvas();
        //        FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth);
        //        FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight);
        //        canvas.Width = visibleSize.Width;
        //        canvas.Height = visibleSize.Height;
        //        canvas.Background = vb;
        //        page.Children.Add(canvas);
        //        yOffset += visibleSize.Height;
        //    }
        //    return fixedDoc;
        //}
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            if (cmbPrinters.SelectedIndex != 0)
            {
                MasterLabelSettingModel model = new MasterLabelSettingModel(0, 0, print_item_code.IsChecked.Value, chk_item_detail.IsChecked.Value, "0", print_item_price.IsChecked.Value, chk_print_barcode.IsChecked.Value, "", "", string.Empty, "", "");
                //MasterLabelSettingModel model = new MasterLabelSettingModel(0, 0, print_item_code.IsChecked.Value, chk_item_detail.IsChecked.Value, "0", print_item_price.IsChecked.Value, chk_print_barcode.IsChecked.Value, bar_code_height.Text, label_sheet_dd.SelectedValue.ToString(), string.Empty, nud_start_row.Value.ToString(), nud_start_column.Value.ToString());
                //  int masterLabelId = controller.SaveUpdateMasterLabel(model);
                List <ProductLabelSettingModel> newStocks = new List <ProductLabelSettingModel>();
                List <ProductLabelSettingModel> Stocks    = lstPurchase.Items.Cast <ProductLabelSettingModel>().Select(x => x).ToList();
                if (Stocks.Any(x => x.ProductCode > 0 && x.Quantity > 0))
                {
                    // stocks = lstPurchase.ItemsSource.Cast<StockModel>().ToList();
                    newStocks.AddRange(Stocks.Where(z => z.ProductCode > 0 && z.Quantity > 0).Select(x =>
                    {
                        return(new ProductLabelSettingModel(0, 0, Convert.ToInt32(x.ProductCode), x.Quantity, x.ProductName));
                        // newStocks.Add(stock);
                    }).ToList());
                }
                MasterPrintInvoice form = new MasterPrintInvoice(model, newStocks);

                PrintDialog printDlg = new PrintDialog();
                //PageMediaSizeName pazesize = (PageMediaSizeName)Enum.Parse(typeof(PageMediaSizeName), CommonConstants._pazeSize + model.LabelSheet);
                //printDlg.PrintTicket.PageMediaSize = new PageMediaSize(pazesize);
                PageSettings obj = GetPrinterPageInfo(this.cmbPrinters.Text);


                #region CommentedCode
                ///  System.Windows.Forms.PrintPreviewDialog printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();

                //  if (printDlg.ShowDialog() == true)

                //  {
                //PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);
                //Size pageSize = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight);
                //Size visibleSize = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
                // FixedDocument fixedDoc = new FixedDocument();
                ////If the toPrint visual is not displayed on screen we neeed to measure and arrange it
                //form.TvBox.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                //form.TvBox.Arrange(new Rect(new Point(0, 0), form.TvBox.DesiredSize));
                ////
                //Size size = form.TvBox.DesiredSize;
                ////Will assume for simplicity the control fits horizontally on the page
                //double yOffset = 0;
                //while (yOffset < size.Height)
                //{
                //    VisualBrush vb = new VisualBrush(form.TvBox);
                //    vb.Stretch = Stretch.None;
                //    vb.AlignmentX = AlignmentX.Left;
                //    vb.AlignmentY = AlignmentY.Top;
                //    vb.ViewboxUnits = BrushMappingMode.Absolute;
                //    vb.TileMode = TileMode.None;
                //    vb.Viewbox = new Rect(0, yOffset, visibleSize.Width, visibleSize.Height);

                //    PageContent pageContent = new PageContent();
                //    FixedPage page = new FixedPage();
                //    ((IAddChild)pageContent).AddChild(page);
                //    fixedDoc.Pages.Add(pageContent);
                //    form.TvBox.Width = printDlg.PrintableAreaWidth; //pageSize.Width;
                //    form.TvBox.Height = pageSize.Height;
                //    Canvas canvas = new Canvas();
                //    FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth);
                //    FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight);
                //    canvas.Width = visibleSize.Width;
                //    canvas.Height = visibleSize.Height;
                //    canvas.Background = vb;
                //    canvas.Margin = new Thickness(2, 2, 2, 2);

                //    page.Children.Add(canvas);
                //    yOffset += visibleSize.Height;
                //}
                //;
                //  return fixedDoc;
                // form.TvBox.MaxWidth = pageSize.Width;
                #endregion
                #region EarlierCode
                //// get selected printer capabilities
                //System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);
                ////get scale of the print wrt to screen of WPF visual

                //double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / this.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
                //              this.ActualHeight);
                ////  //Transform the Visual to scale
                //form.TvBox.LayoutTransform = new ScaleTransform(scale, scale);
                //form.TvBox.Margin = new Thickness(5, 5, 5, 5);
                //form.Height = 1150;
                ////  //get the size of the printer page
                //Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
                ////  //update the layout of the visual to the printer page size.
                //form.TvBox.Height = capabilities.PageImageableArea.ExtentHeight;
                //form.TvBox.Width = capabilities.PageImageableArea.ExtentWidth;
                //form.TvBox.Measure(sz);
                //////  form.Width = 850;
                //form.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

                ////  now print the visual to printer to fit on the one page.
                //for (var i = 0; i <= Convert.ToInt32(model.StartRow); i++)
                //{
                //    if (i == Convert.ToInt32(model.StartRow))
                //    {
                //        printDlg.PrintVisual(form.TvBox, "First Fit to Page WPF Print");
                //    }
                //}
                // printDlg.PrintDocument(fixedDoc.DocumentPaginator, "My Document");


                #endregion

                //PrintDialog pd = new PrintDialog();
                //pd.PrintQueue = new PrintQueue(new PrintServer(), cmbPrinters.Text);
                //if (DialogResult.OK == pd.ShowDialog(this))
                //{
                //    // Send a printer-specific to the printer.
                //    RawPrinterHelper.SendStringToPrinter(cmbPrinters.Text, "Check");
                //}
                //GenerateThermalLabelWorker(form);
                form.TvBox.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                form.TvBox.Arrange(new Rect(new Point(0, 0), form.TvBox.DesiredSize));
                PrintDialog dialog  = new PrintDialog();
                StackPanel  myPanel = new StackPanel();
                myPanel.RenderSize = form.TvBox.DesiredSize;

                foreach (PrintMasterSettingModel item in form.TvBox.Items)
                {
                    TextBlock myBlock = new TextBlock();
                    myBlock.Text          = "Item :" + item.ProductName;
                    myBlock.TextAlignment = System.Windows.TextAlignment.Center;
                    myPanel.Children.Add(myBlock);
                    Image myImage = new Image();
                    myImage.Width   = item.ImageData.Width;
                    myImage.Height  = item.ImageData.Height;
                    myImage.Stretch = Stretch.None;
                    myImage.Source  = item.ImageData;
                    myPanel.Children.Add(myImage);
                    TextBlock myBlock1 = new TextBlock();
                    myBlock1.Text          = "Price :" + item.Price;
                    myBlock1.TextAlignment = System.Windows.TextAlignment.Center;
                    myPanel.Children.Add(myBlock1);
                }
                myPanel.Arrange(new Rect(0, 20, form.TvBox.DesiredSize.Width,
                                         form.TvBox.DesiredSize.Height));
                dialog.PrintQueue = new PrintQueue(new PrintServer(), cmbPrinters.Text);
                //dialog.PrintDocument()
                //  dialog.ShowDialog();

                //System.Windows.Forms.PrintPreviewDialog printPrvDlg = new System.Windows.Forms.PrintPreviewDialog();
                //printPrvDlg.Document = myPanel;
                //printPrvDlg.Width = 1200;
                //printPrvDlg.Height = 800;
                //printPrvDlg.ShowDialog();
                dialog.PrintVisual(myPanel, "A Great Image.");

                //PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);
                //Size pageSize = new Size(obj.Bounds.Width, obj.Bounds.Height);
                //Size visibleSize = new Size(obj.Bounds.Width, obj.Bounds.Height);
                //FixedDocument fixedDoc = new FixedDocument();

                ////If the toPrint visual is not displayed on screen we neeed to measure and arrange it
                //form.TvBox.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                //form.TvBox.Arrange(new Rect(new Point(0, 0), form.TvBox.DesiredSize));
                ////
                //Size size = form.TvBox.DesiredSize;
                ////Will assume for simplicity the control fits horizontally on the page
                //double yOffset = 0;
                //while (yOffset < size.Height)
                //{
                //    VisualBrush vb = new VisualBrush(form.TvBox);
                //    vb.Stretch = Stretch.None;
                //    vb.AlignmentX = AlignmentX.Left;
                //    vb.AlignmentY = AlignmentY.Top;
                //    vb.ViewboxUnits = BrushMappingMode.Absolute;
                //    vb.TileMode = TileMode.None;
                //    vb.Viewbox = new Rect(0, yOffset, visibleSize.Width, visibleSize.Height);
                //    PageContent pageContent = new PageContent();
                //    FixedPage page = new FixedPage();
                //    ((IAddChild)pageContent).AddChild(page);
                //    fixedDoc.Pages.Add(pageContent);
                //    page.Width = pageSize.Width;
                //    page.Height = pageSize.Height;
                //    Canvas canvas = new Canvas();
                //    FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth);
                //    FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight);
                //    canvas.Width = visibleSize.Width;
                //    canvas.Height = visibleSize.Height;
                //    canvas.Background = vb;
                //    page.Children.Add(canvas);
                //    yOffset += visibleSize.Height;
                //}
                ////for (var i = 0; i <= Convert.ToInt32(model.StartRow); i++)
                ////{
                ////    if (i == Convert.ToInt32(model.StartRow))
                ////    {
                ////        printDlg.PrintVisual(form.TvBox, "First Fit to Page WPF Print");
                ////    }
                ////}
                ////printDlg.ShowDialog();
                //printDlg.PrintQueue = new PrintQueue(new PrintServer(), cmbPrinters.Text);
                ////PrintDocument pd=printDlg.
                //printDlg.PrintDocument(fixedDoc.DocumentPaginator, "First Fit to Page WPF Print");
            }
            else
            {
                ConfirmationPopup obj = new ConfirmationPopup((string)Application.Current.Resources["select_printer"], (string)Application.Current.Resources["masterLabel_Header_Popup"], false);
                obj.ShowDialog();
                //CommonFunction.Common.((string)Application.Current.Resources["select_printer"], "", false);
            }
        }
示例#17
0
        Composite
        (
            Double compositeWidth,
            Double compositeHeight,
            String headerText,
            String footerText,
            System.Drawing.Font headerFooterFont,
            IEnumerable <LegendControlBase> legendControls
        )
        {
            Debug.Assert(compositeWidth > 0);
            Debug.Assert(compositeHeight > 0);
            Debug.Assert(headerFooterFont != null);
            Debug.Assert(legendControls != null);
            AssertValid();

            // Note:
            //
            // Don't try taking a shortcut by using
            // NodeXLControl.CopyGraphToBitmap() to get an image of the graph and
            // then compositing the image with the other elements.  That would work
            // if the caller were creating an image, but if it were creating an XPS
            // document, the graph would no longer be scalable.

            Double dScreenDpi =
                WpfGraphicsUtil.GetScreenDpi(m_oNodeXLControl).Width;

            // The NodeXLControl can't be a child of two logical trees, so
            // disconnect it from its parent after saving the current vertex
            // locations.

            m_oLayoutSaver = new LayoutSaver(m_oNodeXLControl.Graph);

            Debug.Assert(m_oNodeXLControl.Parent is Panel);
            m_oParentPanel = (Panel)m_oNodeXLControl.Parent;
            UIElementCollection oParentChildren = m_oParentPanel.Children;

            m_iChildIndex = oParentChildren.IndexOf(m_oNodeXLControl);
            oParentChildren.Remove(m_oNodeXLControl);

            m_oGraphImageScaler = new GraphImageScaler(m_oNodeXLControl);

            m_oGraphImageCenterer = new NodeXLControl.GraphImageCenterer(
                m_oNodeXLControl);

            // The header and footer are rendered as Label controls.  The legend is
            // rendered as a set of Image controls.

            Label oHeaderLabel, oFooterLabel;
            IEnumerable <Image> oLegendImages;
            Double dHeaderHeight, dTotalLegendHeight, dFooterHeight;

            CreateHeaderOrFooterLabel(headerText, compositeWidth, headerFooterFont,
                                      out oHeaderLabel, out dHeaderHeight);

            CreateLegendImages(legendControls, compositeWidth, out oLegendImages,
                               out dTotalLegendHeight);

            CreateHeaderOrFooterLabel(footerText, compositeWidth, headerFooterFont,
                                      out oFooterLabel, out dFooterHeight);

            m_oNodeXLControl.Width = compositeWidth;

            m_oNodeXLControl.Height = Math.Max(10,
                                               compositeHeight - dHeaderHeight - dTotalLegendHeight
                                               - dFooterHeight);

            // Adjust the control's graph scale so that the graph's vertices and
            // edges will be the same relative size in the composite that they are
            // in the control.

            m_oGraphImageScaler.SetGraphScale(
                (Int32)WpfGraphicsUtil.WpfToPx(compositeWidth, dScreenDpi),
                (Int32)WpfGraphicsUtil.WpfToPx(m_oNodeXLControl.Height, dScreenDpi),
                dScreenDpi);

            // Adjust the NodeXLControl's translate transforms so that the
            // composite will be centered on the same point on the graph that the
            // NodeXLControl is centered on.

            m_oGraphImageCenterer.CenterGraphImage(new Size(compositeWidth,
                                                            m_oNodeXLControl.Height));

            StackPanel          oStackPanel         = new StackPanel();
            UIElementCollection oStackPanelChildren = oStackPanel.Children;

            // To avoid a solid black line at the bottom of the header or the top
            // of the footer, which is caused by rounding errors, make the
            // StackPanel background color the same as the header and footer.

            oStackPanel.Background = HeaderFooterBackgroundBrush;

            if (oHeaderLabel != null)
            {
                oStackPanelChildren.Add(oHeaderLabel);
            }

            // Wrap the NodeXLControl in a Grid to clip it.

            m_oGrid              = new Grid();
            m_oGrid.Width        = m_oNodeXLControl.Width;
            m_oGrid.Height       = m_oNodeXLControl.Height;
            m_oGrid.ClipToBounds = true;
            m_oGrid.Children.Add(m_oNodeXLControl);

            oStackPanelChildren.Add(m_oGrid);

            foreach (Image oLegendImage in oLegendImages)
            {
                oStackPanelChildren.Add(oLegendImage);
            }

            if (oFooterLabel != null)
            {
                oStackPanelChildren.Add(oFooterLabel);
            }

            Size oCompositeSize      = new Size(compositeWidth, compositeHeight);
            Rect oCompositeRectangle = new Rect(new Point(), oCompositeSize);

            oStackPanel.Measure(oCompositeSize);
            oStackPanel.Arrange(oCompositeRectangle);
            oStackPanel.UpdateLayout();

            return(oStackPanel);
        }
        void generationWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            int index = (int)e.Argument;

            DateTime now       = DateTime.Now;
            string   photoName = String.Format("daily_{0}.jpg", now.Ticks);

            Dispatcher.BeginInvoke(() =>
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    Stream bgStream = Application.GetResourceStream(new Uri(String.Format("Assets/CalendarTemplate/{0}.jpg", index), UriKind.Relative)).Stream;
                    var container   = new StackPanel()
                    {
                        Width      = Constant.GENERATED_IMAGE_WIDTH,
                        Height     = Constant.GENERATED_IMAGE_HEIGHT,
                        Background = new ImageBrush()
                        {
                            ImageSource = PictureDecoder.DecodeJpeg(bgStream, Constant.GENERATED_IMAGE_WIDTH, Constant.GENERATED_IMAGE_HEIGHT)
                        }
                    };
                    bgStream.Close();

                    var marginLeft = 20;
                    var marginTop  = 50;
                    var offset     = 25;

                    var imageContainer = new Canvas()
                    {
                        Width               = Constant.GENERATED_CALENDAR_WIDTH + offset * 2,
                        Height              = Constant.GENERATED_IMAGE_HEIGHT,
                        Background          = new SolidColorBrush(Colors.Transparent),
                        Margin              = new Thickness(marginLeft, 0, 0, 0),
                        HorizontalAlignment = HorizontalAlignment.Left
                    };

                    var opacityBorder = new Border()
                    {
                        Width      = Constant.GENERATED_CALENDAR_WIDTH + offset * 2,
                        Height     = Constant.GENERATED_IMAGE_HEIGHT,
                        Background = new SolidColorBrush(Colors.Black),
                        Opacity    = 0.5
                    };

                    var calendar = new CalendarForRender()
                    {
                        DataContext = App.ViewModelData,
                        Width       = Constant.GENERATED_CALENDAR_WIDTH,
                        Margin      = new Thickness(offset, marginTop, 0, 0)
                    };
                    //calendar.Calendar.SelectedDate = DateTime.Now;
                    calendar.Calendar.SelectedMonth = DateSelector.SelectedValue.Month;
                    calendar.Calendar.SelectedYear  = DateSelector.SelectedValue.Year;
                    calendar.Calendar.Refresh();

                    imageContainer.Children.Add(opacityBorder);
                    imageContainer.Children.Add(calendar);

                    container.Children.Add(imageContainer);
                    container.Measure(new Size(Constant.GENERATED_IMAGE_WIDTH, Constant.GENERATED_IMAGE_HEIGHT));
                    container.Arrange(new Rect(0, 0, Constant.GENERATED_IMAGE_WIDTH, Constant.GENERATED_IMAGE_HEIGHT));

                    var bitmap = new WriteableBitmap(container, null);
                    bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
                    stream.Seek(0, SeekOrigin.Begin);
                    using (MediaLibrary library = new MediaLibrary())
                    {
                        library.SavePicture(photoName, stream);
                    }
                }
            });
        }
示例#19
0
        public void TestOffset()
        {
            var stackSize  = new Vector3(100, 200, 300);
            var childSize1 = new Vector3(50, 150, 250);
            var childSize2 = new Vector3(150, 250, 350);
            var childSize3 = new Vector3(250, 250, 350);
            var childSize4 = new Vector3(350, 250, 350);

            var stackPanel = new StackPanel {
                Size = stackSize, Orientation = Orientation.Horizontal
            };

            Assert.Equal(Vector3.Zero, stackPanel.Offset);

            var child1 = new StackPanel {
                Size = childSize1
            };
            var child2 = new StackPanel {
                Size = childSize2
            };
            var child3 = new StackPanel {
                Size = childSize3
            };
            var child4 = new StackPanel {
                Size = childSize4
            };

            stackPanel.Children.Add(child1);
            stackPanel.Children.Add(child2);
            stackPanel.Children.Add(child3);
            stackPanel.Children.Add(child4);

            var refenceOffset = Vector3.Zero;

            // non virtualized children
            stackPanel.ScrolllToElement(1);
            stackPanel.Arrange(Vector3.Zero, false);
            refenceOffset[0] -= childSize1.X;
            Assert.Equal(refenceOffset, stackPanel.Offset);

            stackPanel.ScrolllToElement(2.5f);
            stackPanel.Arrange(Vector3.Zero, false);
            refenceOffset[0] -= childSize2.X + childSize3.X / 2;
            Assert.Equal(refenceOffset, stackPanel.Offset);

            stackPanel.ScrollToEnd(Orientation.Horizontal);
            stackPanel.Arrange(Vector3.Zero, false);
            refenceOffset[0] = -childSize1.X - childSize2.X - childSize3.X - childSize4.X + stackPanel.Size.X;
            Assert.True((refenceOffset - stackPanel.Offset).Length() < 0.001);

            // virtualized children
            refenceOffset[0] = 0;
            stackPanel.ScrolllToElement(0);
            stackPanel.ItemVirtualizationEnabled = true;
            stackPanel.Arrange(Vector3.Zero, false);
            Assert.Equal(refenceOffset, stackPanel.Offset);

            refenceOffset[0] = 0;
            stackPanel.ScrolllToElement(1);
            stackPanel.Arrange(Vector3.Zero, false);
            Assert.Equal(refenceOffset, stackPanel.Offset);

            refenceOffset[0] = -childSize3.X / 2;
            stackPanel.ScrolllToElement(2.5f);
            stackPanel.Arrange(Vector3.Zero, false);
            Assert.Equal(refenceOffset, stackPanel.Offset);

            stackPanel.ScrollToEnd(Orientation.Horizontal);
            stackPanel.Arrange(Vector3.Zero, false);
            refenceOffset[0] = -childSize4.X + stackPanel.Size.X;
            Assert.True((refenceOffset - stackPanel.Offset).Length() < 0.001);
        }
示例#20
0
        public void TestScrollToNeighborScreen(bool virtualizeItems)
        {
            var stackSize  = new Vector3(100, 200, 300);
            var childSize1 = new Vector3(50, 150, 250);
            var childSize2 = new Vector3(150, 250, 350);
            var childSize3 = new Vector3(250, 250, 350);

            var stackPanel = new StackPanel {
                Size = stackSize, ItemVirtualizationEnabled = virtualizeItems, Orientation = Orientation.Horizontal
            };

            var child1 = new StackPanel {
                Size = childSize1
            };
            var child2 = new StackPanel {
                Size = childSize2
            };
            var child3 = new StackPanel {
                Size = childSize3
            };

            stackPanel.Children.Add(child1);
            stackPanel.Children.Add(child2);
            stackPanel.Children.Add(child3);

            stackPanel.Arrange(Vector3.Zero, false);

            // pre-arranged
            stackPanel.ScrollToNextPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition);

            stackPanel.ScrollToPreviousPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1 + 2 / 3f);
            stackPanel.ScrollToPreviousPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(1f, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1 + 2 / 3f);
            stackPanel.ScrollToNextPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(2.2f, stackPanel.ScrollPosition);

            // reset scrolling
            stackPanel.ScrollToBeginning(Orientation.Horizontal);
            stackPanel.Arrange(Vector3.Zero, false);

            // post arranged
            stackPanel.InvalidateArrange();
            stackPanel.ScrollToNextPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition);

            stackPanel.InvalidateArrange();
            stackPanel.ScrollToPreviousPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1 + 2 / 3f);
            stackPanel.Arrange(Vector3.Zero, false);
            stackPanel.InvalidateArrange();
            stackPanel.ScrollToPreviousPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(1 + 2 / 3f, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Utilities.AssertAreNearlyEqual(1, stackPanel.ScrollPosition);

            stackPanel.ScrolllToElement(1 + 2 / 3f);
            stackPanel.Arrange(Vector3.Zero, false);
            stackPanel.InvalidateArrange();
            stackPanel.ScrollToNextPage(Orientation.Horizontal);
            Utilities.AssertAreNearlyEqual(1 + 2 / 3f, stackPanel.ScrollPosition);
            stackPanel.Arrange(Vector3.Zero, false);
            Utilities.AssertAreNearlyEqual(2.2f, stackPanel.ScrollPosition);
        }
示例#21
0
        public static async Task <StorageFile> TakeScreenshot()
        {
            StackPanel sp = new StackPanel()
            {
                Background  = new SolidColorBrush(Windows.UI.Colors.Teal),
                Width       = 200,
                Height      = 600,
                Orientation = Orientation.Vertical
            };

            TextBlock txtLine1 = new TextBlock()
            {
                Text          = "Text Line 1",
                Foreground    = new SolidColorBrush(Windows.UI.Colors.White),
                Width         = 200,
                Height        = 30,
                FontSize      = 32,
                TextAlignment = TextAlignment.Left,
                Margin        = new Thickness(9, 3, 0, 3)
            };

            TextBlock txtLine2 = new TextBlock {
                Text          = "Text Line 2",
                Foreground    = new SolidColorBrush(Windows.UI.Colors.White),
                Width         = 200,
                Height        = 30,
                FontSize      = 32,
                TextAlignment = TextAlignment.Left,
                Margin        = new Thickness(9, 3, 0, 3)
            };

            sp.Children.Add(txtLine1);
            sp.Children.Add(txtLine2);

            sp.UpdateLayout();
            sp.Measure(new Size(200, 200));
            sp.Arrange(new Rect(0, 0, 200, 200));
            sp.UpdateLayout();

            //now lets render this stackpanel on image
            try {
                RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
                await renderTargetBitmap.RenderAsync(sp, 200, 200);

                var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();

                StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                var           tileFile      = await storageFolder.CreateFileAsync("image.png", CreationCollisionOption.ReplaceExisting);

                // Encode the image to the selected file on disk
                using (var fileStream = await tileFile.OpenAsync(FileAccessMode.ReadWrite)) {
                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                    encoder.SetPixelData(
                        BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Ignore,
                        (uint)renderTargetBitmap.PixelWidth,
                        (uint)renderTargetBitmap.PixelHeight,
                        DisplayInformation.GetForCurrentView().LogicalDpi,
                        DisplayInformation.GetForCurrentView().LogicalDpi,
                        pixelBuffer.ToArray());

                    await encoder.FlushAsync();
                }
                return(tileFile);
            } catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                //new MessageDialog(ex.Message, "Error").ShowAsync();
                return(null);
            }
        }