示例#1
0
        /// <summary>
        /// Export the specified plot model to an xaml string.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="background">The background.</param>
        /// <returns>A xaml string.</returns>
        public static string ExportToString(PlotModel model, double width, double height, OxyColor background = null)
        {
            var g = new Grid();
            if (background != null)
            {
                g.Background = background.ToBrush();
            }

            var c = new Canvas();
            g.Children.Add(c);

            var size = new Size(width, height);
            g.Measure(size);
            g.Arrange(new Rect(0, 0, width, height));
            g.UpdateLayout();

            var rc = new ShapesRenderContext(c) { UseStreamGeometry = false };
            model.Update();
            model.Render(rc, width, height);

            var sb = new StringBuilder();
            using (var sw = new StringWriter(sb))
            {
                var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true });
                XamlWriter.Save(c, xw);
            }

            return sb.ToString();
        }
示例#2
0
        void create()
        {
            Grid grid = new Grid();
            grid.HorizontalAlignment = HorizontalAlignment.Center;
            grid.VerticalAlignment = VerticalAlignment.Center;
            grid.Background = null;

            Rating ratingControl = new Rating();

            ratingControl.HorizontalAlignment = HorizontalAlignment.Left;
            ratingControl.VerticalAlignment = VerticalAlignment.Top;
            ratingControl.ItemCount = 5;
            ratingControl.Foreground = new SolidColorBrush(Colors.Red);
            ratingControl.Background = null;
            ratingControl.IsReadOnly = true;
            ratingControl.SelectionMode = RatingSelectionMode.Continuous;

            double scale = 0.6;
            ratingControl.LayoutTransform = new ScaleTransform(scale, scale);

            grid.Children.Add(ratingControl);

            int i = 0;

            double nrStars = 0;
            do
            {
                ratingControl.Value = nrStars;

                grid.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                grid.Arrange(new Rect(new Size(double.MaxValue, double.MaxValue)));
                Rect size = VisualTreeHelper.GetDescendantBounds(ratingControl);
                //grid.Arrange(new Rect(new Size(size.Width, size.Height)));

                RenderTargetBitmap bitmap = new RenderTargetBitmap((int)(size.Width * scale), (int)(size.Height * scale),
                    96, 96, PixelFormats.Default);

                Window dummy = new Window();
                dummy.Content = grid;
                dummy.SizeToContent = SizeToContent.WidthAndHeight;
                dummy.Show();

                bitmap.Render(ratingControl);

                RatingBitmap.Add(bitmap);

                nrStars += 1.0 / 5;
               
                BitmapEncoder encoder = new PngBitmapEncoder();

                encoder.Frames.Add(BitmapFrame.Create(bitmap, null, null, null));

                FileStream outputFile = new FileStream("d:\\" + i + "stars.png", FileMode.Create);

                encoder.Save(outputFile);
                
                i++;

            } while (nrStars <= 1);
        }
示例#3
0
        void this_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (!isLoaded)
            {
                Tab1_Unselected.Measure(e.NewSize);
                collapsedWidth1 = Tab1_Unselected.DesiredSize.Width;

                Tab2_Unselected.Measure(e.NewSize);
                collapsedWidth2 = Tab2_Unselected.DesiredSize.Width;

                Tab1_Unselected.Visibility = Visibility.Collapsed;
                Tab2_Selected.Visibility   = Visibility.Collapsed;

                isLoaded = true;
            }

            var expandedWidth1 = e.NewSize.Width - collapsedWidth2;
            var expandedWidth2 = e.NewSize.Width - collapsedWidth1;

            var select1Storyboard = VisualStateHelper.FindStoryboard(LayoutRoot, "TabStates", "Select1");
            var expand1           = (DoubleAnimation)select1Storyboard.Children.FirstOrDefault(an => Storyboard.GetTargetName(an) == "Tab1" && Storyboard.GetTargetProperty(an).Path == "Width");

            expand1.To = expandedWidth1;
            var collapse2 = (DoubleAnimation)select1Storyboard.Children.FirstOrDefault(an => Storyboard.GetTargetName(an) == "Tab2" && Storyboard.GetTargetProperty(an).Path == "Width");

            collapse2.To = collapsedWidth2;

            var select2Storyboard = VisualStateHelper.FindStoryboard(LayoutRoot, "TabStates", "Select2");
            var expand2           = (DoubleAnimation)select2Storyboard.Children.FirstOrDefault(an => Storyboard.GetTargetName(an) == "Tab2" && Storyboard.GetTargetProperty(an).Path == "Width");

            expand2.To = expandedWidth2;
            var collapse1 = (DoubleAnimation)select2Storyboard.Children.FirstOrDefault(an => Storyboard.GetTargetName(an) == "Tab1" && Storyboard.GetTargetProperty(an).Path == "Width");

            collapse1.To = collapsedWidth1;

            Tab1_Selected.Width = expandedWidth1;
            Tab2_Selected.Width = expandedWidth2;

            if (selectedTab == 1)
            {
                Tab1.Width = expandedWidth1;
            }
            else if (selectedTab == 2)
            {
                Tab2.Width = expandedWidth2;
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var icon = (sender as Button).DataContext as IconWrapper;

            var grid = new Grid {Height = 36, Width = 36, Background = Brushes.White};
            var visual = new Rectangle {Fill = icon.Icon};
            grid.Children.Add(visual);
            var renderBitmap = new RenderTargetBitmap(36, 36, 96d, 96d, PixelFormats.Pbgra32);

            var size = new Size(36, 36);
            grid.Measure(size);
            grid.Arrange(new Rect(size));

            // Update the layout for the surface. This should flush out any layout queues that hold a reference.

            renderBitmap.Render(grid);

            Clipboard.SetImage(renderBitmap);
        }
		private void OnMouseMove(object sender, MouseEventArgs e)
		{
			var popup = GetPopupTipWindow();
			if (popup.IsOpen)
				popup.Hide();

			Point screenPoint = e.GetPosition(plotter.CentralGrid);
			Point viewportPoint = screenPoint.ScreenToData(plotter.Transform);

			var tooltip = GetTooltipForPoint(viewportPoint);
			if (tooltip == null) return;

			popup.VerticalOffset = screenPoint.Y + 20;
			popup.HorizontalOffset = screenPoint.X;

			popup.ShowDelayed(TimeSpan.FromSeconds(0));

			Grid grid = new Grid();

			Rectangle rect = new Rectangle
			{
				Stroke = Brushes.Black,
				Fill = SystemColors.InfoBrush
			};

			StackPanel panel = new StackPanel();
			panel.Orientation = Orientation.Vertical;
			panel.Children.Add(tooltip);
			panel.Margin = new Thickness(4, 2, 4, 2);

			var textBlock = new TextBlock();
			textBlock.Text = String.Format("Location: {0:F2}, {1:F2}", viewportPoint.X, viewportPoint.Y);
			textBlock.Foreground = SystemColors.GrayTextBrush;
			panel.Children.Add(textBlock);

			grid.Children.Add(rect);
			grid.Children.Add(panel);
			grid.Measure(SizeHelper.CreateInfiniteSize());
			popup.Child = grid;
		}
        public void RenderAndSave(ImageRendererArguments args, out string fileName)
        {
            var mainContainer = new Grid();

            mainContainer.Children.Add(args.UiContainer);
            mainContainer.Measure(new Size(args.Width, args.Height));
            mainContainer.Arrange(new Rect(0, 0, args.Width, args.Height));
            mainContainer.UpdateLayout();

            var encoder = new PngBitmapEncoder();
            var render = RenderBitmap(mainContainer, args.Dpi);

            var workingDirectory = @"c:\temp";
            fileName = Path.Combine(workingDirectory, $"dwg_{Guid.NewGuid()}.png");

            render.Render(mainContainer);
            encoder.Frames.Add(BitmapFrame.Create(render));
            using (var s = File.Open(fileName, FileMode.Create))
            {
                encoder.Save(s);
            }
        }
示例#7
0
文件: GridTest.cs 项目: kangaroo/moon
		public void ComplexLayout2 ()
		{
			Grid g = new Grid ();

			RowDefinition rdef;
			ColumnDefinition cdef;

			rdef = new RowDefinition ();
			rdef.Height = new GridLength (200);
			g.RowDefinitions.Add (rdef);

			cdef = new ColumnDefinition ();
			cdef.Width = new GridLength (200);
			g.ColumnDefinitions.Add (cdef);

			g.Margin = new Thickness (5);

			LayoutPoker c = new LayoutPoker ();

			Grid.SetRow (c, 0);
			Grid.SetColumn (c, 0);

			g.Children.Add (c);

			c.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));

			// first test with the child sized larger than the row/column definitions
			c.Width = 400;
			c.Height = 400;

			g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));

			Assert.AreEqual (400, c.Width);
			Assert.AreEqual (400, c.Height);

			Assert.AreEqual (new Size (200, 200), c.DesiredSize, "c DesiredSize0");
			Assert.AreEqual (new Size (400, 400), c.MeasureArg, "c MeasureArg0");
			Assert.AreEqual (new Size (210, 210), g.DesiredSize, "grid DesiredSize0");

			g.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (100, 100), g.DesiredSize, "grid DesiredSize1");
			Assert.AreEqual (new Size (400, 400), c.MeasureArg, "c MeasureArg");
			Assert.AreEqual (new Size (200, 200), c.DesiredSize, "c DesiredSize1");

			// now test with the child sized smaller than the row/column definitions
			c.Width = 100;
			c.Height = 100;

			g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));

			Assert.AreEqual (new Size (100, 100), c.MeasureArg, "c MeasureArg2");
			Assert.AreEqual (new Size (210, 210), g.DesiredSize, "grid DesiredSize2");
		}
示例#8
0
文件: GridTest.cs 项目: kangaroo/moon
		public void ChildlessMargin_RowDefinition_Height_starSize_constSize_multiRow ()
		{
			Grid g = new Grid ();

			RowDefinition def;

			def = new RowDefinition ();
			def.Height = new GridLength (2, GridUnitType.Star);
			g.RowDefinitions.Add (def);

			def = new RowDefinition ();
			def.Height = new GridLength(200);
			g.RowDefinitions.Add (def);

			g.Margin = new Thickness (5);

			g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));

			Assert.AreEqual (new Size (10, 210), g.DesiredSize, "DesiredSize");

			g.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (10, 100), g.DesiredSize, "DesiredSize");
		}
示例#9
0
文件: GridTest.cs 项目: kangaroo/moon
		public void ChildlessMargin_RowDefinition_Height_autoSize_singleRow ()
		{
			Grid g = new Grid ();

			RowDefinition def;

			def = new RowDefinition ();
			def.Height = GridLength.Auto;
			g.RowDefinitions.Add (def);

			g.Margin = new Thickness (5);

			g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));

			Assert.AreEqual (new Size (10, 10), g.DesiredSize, "DesiredSize");

			g.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (10, 10), g.DesiredSize, "DesiredSize");
		}
示例#10
0
文件: GridTest.cs 项目: kangaroo/moon
		public void ChildlessMargin_ColumnDefinition_Width_starSize_constSize_multiColumn ()
		{
			Grid g = new Grid ();

			ColumnDefinition def;

			def = new ColumnDefinition ();
			def.Width = new GridLength (2, GridUnitType.Star);
			g.ColumnDefinitions.Add (def);

			def = new ColumnDefinition ();
			def.Width = new GridLength(200);
			g.ColumnDefinitions.Add (def);

			g.Margin = new Thickness (5);

			g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));

			Assert.AreEqual (new Size (210, 10), g.DesiredSize, "DesiredSize");

			g.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (100, 10), g.DesiredSize, "DesiredSize");
		}
示例#11
0
文件: GridTest.cs 项目: kangaroo/moon
		public void ChildlessMargin_ColumnDefinition_Width_autoSize_singleColumn ()
		{
			Grid g = new Grid ();

			ColumnDefinition def;

			def = new ColumnDefinition ();
			def.Width = GridLength.Auto;
			g.ColumnDefinitions.Add (def);

			g.Margin = new Thickness (5);

			g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));

			Assert.AreEqual (new Size (10, 10), g.DesiredSize, "DesiredSize");

			g.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (10, 10), g.DesiredSize, "DesiredSize");
		}
示例#12
0
文件: GridTest.cs 项目: kangaroo/moon
		public void ArrangeTest_TwoChildren ()
		{
			Grid g = new Grid ();

			RowDefinition rdef;
			ColumnDefinition cdef;

			rdef = new RowDefinition ();
			rdef.Height = new GridLength (50);
			g.RowDefinitions.Add (rdef);

			cdef = new ColumnDefinition ();
			cdef.Width = new GridLength (100);
			g.ColumnDefinitions.Add (cdef);

			cdef = new ColumnDefinition ();
			cdef.Width = new GridLength (20);
			g.ColumnDefinitions.Add (cdef);

			g.Margin = new Thickness (5);

			var ra = new Border ();
			var rb = new Border ();

			Grid.SetRow (ra, 0);
			Grid.SetColumn (ra, 0);

			Grid.SetRow (rb, 0);
			Grid.SetColumn (rb, 1);

			g.Children.Add (ra);
			g.Children.Add (rb);

			g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));

			Assert.AreEqual (new Size (0,0), ra.DesiredSize, "ra actual after measure");
			Assert.AreEqual (new Size (0,0), rb.DesiredSize, "rb actual after measure");
			Assert.AreEqual (new Size (130,60), g.DesiredSize, "g desired 1");

			g.Arrange (new Rect (0,0,g.DesiredSize.Width,g.DesiredSize.Height));

			Assert.AreEqual (new Size (0,0), ra.DesiredSize, "ra desired 0");
			Assert.AreEqual (new Size (130,60), g.DesiredSize, "g desired 1");

			Assert.AreEqual (new Rect (0,0,100,50).ToString (), LayoutInformation.GetLayoutSlot (ra).ToString(), "slot");
			Assert.AreEqual (new Size (100,50), new Size (ra.ActualWidth, ra.ActualHeight), "ra actual after arrange");
			Assert.AreEqual (new Size (20,50), new Size (rb.ActualWidth, rb.ActualHeight), "rb actual after arrange");
			Assert.AreEqual (new Size (120,50), new Size (g.ActualWidth, g.ActualHeight), "g actual after arrange");
		}
        /// <summary>
        /// This method constructs the document page (visual) to print
        /// </summary>
        private DocumentPage ConstructPage(Grid content, int pageNumber)
        {
            if (content == null)
                return null;

            //Build the page inc header and footer
            Grid pageGrid = new Grid();

            //Header row
            AddGridRow(pageGrid, GridLength.Auto);

            //Content row
            AddGridRow(pageGrid, new GridLength(1.0d, GridUnitType.Star));

            //Footer row
            AddGridRow(pageGrid, GridLength.Auto);

            ContentControl pageHeader = new ContentControl();
            pageHeader.Content = this.CreateDocumentHeader();
            pageGrid.Children.Add(pageHeader);

            if (content != null)
            {
                content.SetValue(Grid.RowProperty, 1);
                pageGrid.Children.Add(content);
            }

            ContentControl pageFooter = new ContentControl();
            pageFooter.Content = CreateDocumentFooter(pageNumber + 1);
            pageFooter.SetValue(Grid.RowProperty, 2);

            pageGrid.Children.Add(pageFooter);

            double width = this.PageSize.Width - (this.PageMargin.Left + this.PageMargin.Right);
            double height = this.PageSize.Height - (this.PageMargin.Top + this.PageMargin.Bottom);

            pageGrid.Measure(new Size(width, height));
            pageGrid.Arrange(new Rect(this.PageMargin.Left, this.PageMargin.Top, width, height));

            //return new DocumentPage(pageGrid);
            return new DocumentPage(pageGrid, PageSize, new Rect(content.DesiredSize), new Rect(content.DesiredSize));
        }
示例#14
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void AutoRow_StarCol()
		{
			var g = new Grid();
			var child = ContentControlWithChild ();
			g.RowDefinitions.Add(new RowDefinition { Height = Star });
			g.RowDefinitions.Add(new RowDefinition { Height = Star, MaxHeight = 20 });

			g.AddChild(child, 0, 0, 1, 1);
			g.Measure(new Size(100, 100));
			Assert.AreEqual(new Size(100, 80), child.MeasureOverrideArg, "#1");
		}
示例#15
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void ExpandStars_NoRowsOrCols ()
		{
			// If the rows/cols are autogenerated, we still expand them
			Grid grid = new Grid ();
			grid.Children.Add (new Rectangle { Width = 50, Height = 50 });

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

			Assert.AreEqual (200, grid.ActualWidth, "#1");
			Assert.AreEqual (200, grid.ActualHeight, "#2");
		}
示例#16
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void StarRowsWithChild2_NoSpan_ExplicitSize ()
		{
			// Check what happens when there are two explicit rows and no explicit column
			Grid grid = new Grid {
				Width = 75,
				Height = 75,
				HorizontalAlignment = HorizontalAlignment.Center,
				VerticalAlignment = VerticalAlignment.Bottom,
			};
			grid.AddRows (new GridLength (1, GridUnitType.Star), new GridLength (1, GridUnitType.Star));
			grid.Children.Add (new MyContentControl (50, 50));

			// Initial values
			Assert.AreEqual (new Size (0, 0), grid.DesiredSize, "#1");
			grid.CheckRowHeights ("#2", 0, 0);

			// After measure
			grid.Measure (Infinity);
			grid.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height));
			Assert.AreEqual (new Size (75, 75), grid.DesiredSize, "#3");
			grid.CheckRowHeights ("#4", 37.5, 37.5);

			// Measure again
			grid.Measure (new Size (100, 100));
			grid.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height));
			Assert.AreEqual (new Size (75, 75), grid.DesiredSize, "#5");
			grid.CheckRowHeights ("#6", 37.5, 37.5);
		}
示例#17
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void ExpandInArrange_OutsideTree_GridParent_UnfixedSize ()
		{
			// We always expand star rows if we're not in the live tree
			// with a parent
			var parent = new Grid ();

			// Measure with infinity and check results.
			MyGrid grid = new MyGrid ();
			grid.AddRows (Star);
			grid.AddColumns (Star);
			grid.AddChild (ContentControlWithChild (), 0, 0, 1, 1);

			parent.Children.Add (grid);

			parent.Measure (Infinity);
			grid.CheckMeasureArgs ("#1", Infinity);
			grid.CheckMeasureResult ("#2", new Size (50, 50));
			Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#3");

			// When we pass in the desired size as the arrange arg,
			// the rows/cols use that as their height/width
			parent.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height));
			grid.CheckArrangeArgs ("#4", grid.DesiredSize);
			grid.CheckArrangeResult ("#5", grid.DesiredSize);
			grid.CheckRowHeights ("#6", grid.DesiredSize.Height);
			grid.CheckColWidths ("#7", grid.DesiredSize.Width);

			// If we pass in twice the desired size, the rows/cols consume that too
			grid.Reset ();
			parent.Arrange (new Rect (0, 0, 100, 100));
			grid.CheckMeasureArgs ("#8"); // No remeasures
			grid.CheckArrangeArgs ("#9", new Size (100, 100));
			grid.CheckArrangeResult ("#10", new Size (100, 100));
			grid.CheckRowHeights ("#11", 100);
			grid.CheckColWidths ("#12", 100);

			// If we measure with a finite size, the rows/cols still expand
			// to consume the available space
			grid.Reset ();
			parent.Measure (new Size (1000, 1000));
			grid.CheckMeasureArgs ("#13", new Size (1000, 1000));
			grid.CheckMeasureResult ("#14", new Size (50, 50));
			Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#15");

			// When we pass in the desired size as the arrange arg,
			// the rows/cols use that as their height/width
			parent.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height));
			grid.CheckArrangeArgs ("#16", grid.DesiredSize);
			grid.CheckArrangeResult ("#17", grid.DesiredSize);
			grid.CheckRowHeights ("#18", grid.DesiredSize.Height);
			grid.CheckColWidths ("#19", grid.DesiredSize.Width);

			// If we pass in twice the desired size, the rows/cols consume that too
			grid.Reset ();
			parent.Arrange (new Rect (0, 0, 100, 100));
			grid.CheckMeasureArgs ("#20"); // No remeasures
			grid.CheckArrangeArgs ("#21", new Size (100, 100));
			grid.CheckArrangeResult ("#22", new Size (100, 100));
			grid.CheckRowHeights ("#23", 100);
			grid.CheckColWidths ("#24", 100);
		}
示例#18
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void StarRowsWithChild_NoSpan_ExplicitSize ()
		{
			// Check what happens if there is no explicit ColumnDefinition added
			Grid grid = new Grid {
				Width = 75,
				Height = 75,
				HorizontalAlignment = HorizontalAlignment.Center,
				VerticalAlignment = VerticalAlignment.Bottom,
			};
			grid.AddRows (new GridLength (1, GridUnitType.Star));
			grid.Children.Add (new MyContentControl (50, 50));

			// Initial values
			Assert.AreEqual (new Size (0, 0), grid.DesiredSize, "#1");
			Assert.AreEqual (0, grid.RowDefinitions [0].ActualHeight, "#2");

			// After measure
			grid.Measure (Infinity);
			grid.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height));
			Assert.AreEqual (new Size (75, 75), grid.DesiredSize, "#4");
			Assert.AreEqual (75, grid.RowDefinitions [0].ActualHeight, "#5");

			// Measure again
			grid.Measure (new Size (100, 100));
			grid.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height));
			Assert.AreEqual (new Size (75, 75), grid.DesiredSize, "#7");
			Assert.AreEqual (75, grid.RowDefinitions [0].ActualHeight, "#8");
		}
示例#19
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void StarRowsWithChild2 ()
		{
			// Check what happens when there are two explicit rows and no explicit column
			Grid grid = new Grid ();
			grid.AddRows (new GridLength (1, GridUnitType.Star), new GridLength (1, GridUnitType.Star));
			grid.Children.Add (new MyContentControl (50, 50));

			// Initial values
			Assert.AreEqual (new Size (0, 0), grid.DesiredSize, "#1");
			grid.CheckRowHeights ("#2", 0, 0);

			// After measure
			grid.Measure (Infinity);
			grid.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height));
			Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#3");
			grid.CheckRowHeights ("#4", 50, 0);

			// Measure again
			grid.Measure (new Size (100, 100));
			grid.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height));
			Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#5");
			grid.CheckRowHeights ("#6", 50, 0);
		}
示例#20
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void MeasureStarRowsNoChild ()
		{
			// Measuring the rows initialises the sizes to Infinity for 'star' elements
			double inf = double.PositiveInfinity;
			Grid grid = new Grid ();
			grid.AddRows (new GridLength (1, GridUnitType.Star));
			grid.AddColumns (new GridLength (1, GridUnitType.Star));

			// Initial values
			Assert.AreEqual (new Size (0, 0), grid.DesiredSize, "#1");
			Assert.AreEqual (0, grid.RowDefinitions [0].ActualHeight, "#2");
			Assert.AreEqual (0, grid.ColumnDefinitions [0].ActualWidth, "#3");

			// After measure
			grid.Measure (Infinity);
			Assert.AreEqual (new Size (0, 0), grid.DesiredSize, "#4");
			Assert.AreEqual (inf, grid.RowDefinitions [0].ActualHeight, "#5");
			Assert.AreEqual (inf, grid.ColumnDefinitions [0].ActualWidth, "#6");

			// Measure again
			grid.Measure (new Size (100, 100));
			Assert.AreEqual (new Size (0, 0), grid.DesiredSize, "#7");
			Assert.AreEqual (inf, grid.RowDefinitions [0].ActualHeight, "#8");
			Assert.AreEqual (inf, grid.ColumnDefinitions [0].ActualWidth, "#9");
		}
示例#21
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void MeasureStarRowsWithChild ()
		{
			// Check what happens if there is no explicit ColumnDefinition added
			Grid grid = new Grid ();
			grid.AddRows (new GridLength (1, GridUnitType.Star));
			grid.Children.Add (new MyContentControl (50, 50));

			// Initial values
			Assert.AreEqual (new Size (0, 0), grid.DesiredSize, "#1");
			Assert.AreEqual (0, grid.RowDefinitions [0].ActualHeight, "#2");

			// After measure
			grid.Measure (Infinity);
			Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#4");
			Assert.AreEqual (inf, grid.RowDefinitions [0].ActualHeight, "#5");

			// Measure again
			grid.Measure (new Size (100, 100));
			Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#7");
			Assert.AreEqual (100, grid.RowDefinitions [0].ActualHeight, "#8");
		}
        protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
        {
            base.OnMouseMove(e);

            var popup = GetPopupTipWindow();
            if (popup.IsOpen)
                popup.Hide();

            if (bitmapInvalidated) return;

            Point p = e.GetPosition(this);
            Point dp = p.ScreenToData(Plotter2D.Transform);

            var tooltip = GetTooltipForPoint(p, completedRequest.Visible, completedRequest.Output);
            if (tooltip == null) return;

            popup.VerticalOffset = p.Y + 20;
            popup.HorizontalOffset = p.X;

            popup.ShowDelayed(new TimeSpan(0, 0, 1));

            Grid grid = new Grid();

            Rectangle rect = new Rectangle
            {
                Stroke = Brushes.Black,
                Fill = SystemColors.InfoBrush
            };

            StackPanel sp = new StackPanel();
            sp.Orientation = Orientation.Vertical;
            sp.Children.Add(tooltip);
            sp.Margin = new Thickness(4, 2, 4, 2);

            var tb = new TextBlock();
            tb.Text = String.Format("Location: {0:F2}, {1:F2}", dp.X, dp.Y);
            tb.Foreground = SystemColors.GrayTextBrush;
            sp.Children.Add(tb);

            grid.Children.Add(rect);
            grid.Children.Add(sp);
            grid.Measure(SizeHelper.CreateInfiniteSize());
            popup.Child = grid;
        }
示例#23
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void UnfixedGridAllStar ()
		{
			// Check the widths/heights of the rows/cols without specifying a size for the grid
			// Measuring the rows initialises the sizes to Infinity for 'star' elements
			Grid grid = new Grid ();
			grid.AddRows (new GridLength (1, GridUnitType.Star));
			grid.AddColumns (new GridLength (1, GridUnitType.Star));

			// Initial values
			Assert.AreEqual (new Size (0, 0), grid.DesiredSize, "#1");
			Assert.AreEqual (0, grid.RowDefinitions [0].ActualHeight, "#2");
			Assert.AreEqual (0, grid.ColumnDefinitions [0].ActualWidth, "#3");

			// After measure
			grid.Measure (Infinity);
			grid.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height));
			Assert.AreEqual (new Size (0, 0), grid.DesiredSize, "#4");
			Assert.AreEqual (0, grid.RowDefinitions [0].ActualHeight, "#5");
			Assert.AreEqual (0, grid.ColumnDefinitions [0].ActualWidth, "#6");

			// Measure again
			grid.Measure (new Size (100, 100));
			grid.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height));
			Assert.AreEqual (new Size (0, 0), grid.DesiredSize, "#7");
			Assert.AreEqual (0, grid.RowDefinitions [0].ActualHeight, "#8");
			Assert.AreEqual (0, grid.ColumnDefinitions [0].ActualWidth, "#9");
		}
示例#24
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void StarStarRows_LimitedHeight_RowSpan_InfiniteSpace()
		{
			var grid = new Grid();
			grid.RowDefinitions.Add(new RowDefinition { Height = Star });
			grid.RowDefinitions.Add(new RowDefinition { MaxHeight = 20, Height = Star });

			var child1 = ContentControlWithChild();
			var child2 = ContentControlWithChild();
			(child1.Content as FrameworkElement).Height = 50;
			(child2.Content as FrameworkElement).Height = 70;
			grid.AddChild(child1, 0, 0, 1, 1);
			grid.AddChild(child2, 0, 0, 2, 1);

			grid.Measure(Infinity);
			Assert.AreEqual(Infinity, child1.MeasureOverrideArg, "#1");
			Assert.AreEqual(Infinity, child2.MeasureOverrideArg, "#2");
			Assert.AreEqual(new Size (50, 70), grid.DesiredSize, "#3");
		}
示例#25
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void StarRow_AutoStarCol_LimitedWidth()
		{
			var g = new Grid();
			var child = ContentControlWithChild();

			g.RowDefinitions.Add(new RowDefinition { Height = Star });
			g.ColumnDefinitions.Add(new ColumnDefinition { Width = Auto });
			g.ColumnDefinitions.Add(new ColumnDefinition { Width = Star, MaxWidth = 20 });
			g.AddChild(child, 0, 0, 1, 1);

			g.Measure(new Size(100, 100));
			Assert.AreEqual(new Size(inf, 100), child.MeasureOverrideArg, "#1");
		}
示例#26
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void StarStarRows_LimitedHeight_RowSpan_ExactSpace()
		{
			var grid = new Grid();
			grid.RowDefinitions.Add(new RowDefinition { Height = Star });
			grid.RowDefinitions.Add(new RowDefinition { MaxHeight = 20, Height = Star });

			var child1 = ContentControlWithChild();
			var child2 = ContentControlWithChild();
			(child1.Content as FrameworkElement).Height = 50;
			(child2.Content as FrameworkElement).Height = 70;

			grid.AddChild(child1, 0, 0, 1, 1);
			grid.AddChild(child2, 0, 0, 2, 1);

			Action<Size> sized = delegate {
				Assert.AreEqual(50, grid.RowDefinitions[0].ActualHeight, "#row 0 sized");
				Assert.AreEqual(20, grid.RowDefinitions[1].ActualHeight, "#row 1 sized");
			};

			child1.MeasureHook = sized;
			child2.MeasureHook = sized;
			grid.Measure(new Size(70, 70));

			// The row definitions have already been fully sized before the first
			// call to measure a child
			Assert.AreEqual(new Size(70, 50), child1.MeasureOverrideArg, "#1");
			Assert.AreEqual(new Size(70, 70), child2.MeasureOverrideArg, "#2");
			Assert.AreEqual(new Size(50, 70), grid.DesiredSize, "#3");
		}
示例#27
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void MeasureAutoAndFixedRows ()
		{
			Grid grid = new Grid { };

			grid.AddColumns (new GridLength (50), new GridLength (50));
			grid.AddRows (new GridLength (20), new GridLength (20));
			grid.AddChild (new MyContentControl (50, 50), 0, 1, 2, 1);

			grid.Measure (Infinity);
			grid.CheckRowHeights ("#1", 20, 20);
			grid.CheckMeasureSizes ("#2", new Size (50, 40));
			Assert.AreEqual (new Size (100, 40), grid.DesiredSize, "#3");

			grid.RowDefinitions [0].Height = new GridLength (30);
			grid.Measure (Infinity);
			grid.CheckRowHeights ("#4", 30, 20);
			grid.CheckMeasureSizes ("#5", new Size (50, 50));
			Assert.AreEqual (new Size (100, 50), grid.DesiredSize, "#6");

			grid.RowDefinitions.Insert (0, new RowDefinition { Height = GridLength.Auto });
			grid.Measure (Infinity);
			grid.CheckRowHeights ("#7", double.PositiveInfinity, 30, 20);
			grid.CheckMeasureSizes ("#8", new Size (50, double.PositiveInfinity));
			Assert.AreEqual (new Size (100, 70), grid.DesiredSize, "#9");

			grid.Children.Clear ();
			grid.AddChild (new MyContentControl (50, 150), 0, 1, 2, 1);
			grid.Measure (Infinity);
			grid.CheckDesired ("#13", new Size (50, 150));
			grid.CheckRowHeights ("#10", double.PositiveInfinity, 30, 20);
			grid.CheckMeasureSizes ("#11", new Size (50, double.PositiveInfinity));
			grid.CheckMeasureResult ("#12", new Size (50, 150));
			Assert.AreEqual (new Size (100, 170), grid.DesiredSize, "#12");
		}
示例#28
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void ChildInvalidatesGrid ()
		{
			var child = new MyContentControl (50, 50);
			Grid grid = new Grid ();
			grid.Children.Add (child);
			grid.Measure (new Size (100, 100));
			Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#1");

			((FrameworkElement) child.Content).Height = 60;
			((FrameworkElement) child.Content).Width = 10;

			grid.Measure (new Size (100, 100));
			Assert.AreEqual (new Size (10, 60), grid.DesiredSize, "#2");
		}
示例#29
0
文件: GridTestAuto.cs 项目: dfr0/moon
		public void ExpandStars_NoRowsOrCols2 ()
		{
			// We don't expand autogenerated rows/cols if we don't have Alignment.Stretch
			Grid grid = new Grid { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };
			grid.Children.Add (new Rectangle { Width = 50, Height = 50 });

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

			Assert.AreEqual (50, grid.ActualWidth, "#1");
			Assert.AreEqual (50, grid.ActualHeight, "#2");
		}
示例#30
-1
文件: Printing.cs 项目: Stankim/Onion
        public static void PrintVisual(Grid g)
        {
            printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == false)
                return;
            FrameworkElement e = g as FrameworkElement;
            Transform originalScale = e.LayoutTransform;   
           
            //get selected printer capabilities
            PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
            //get scale of the print wrt to screen of WPF visual
            double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / g.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
            g.ActualHeight);
            //Transform the Visual to scale
            g.LayoutTransform = new ScaleTransform(scale, scale);
            //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.

            g.Measure(sz);
            g.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

            //now print the visual to printer to fit on the one page.
           
            printDialog.PrintVisual(g, "Onion Smart Solutions");

            e.LayoutTransform = originalScale;
        }
示例#31
-1
        void PrintOnClick(object sender, RoutedEventArgs args)
        {
            PrintDialog dlg = new PrintDialog();
            if (dlg.ShowDialog().GetValueOrDefault())
            {
                Grid grid = new Grid();
                for (int i = 0; i < 5; i++)
                {
                    ColumnDefinition coldef = new ColumnDefinition();
                    coldef.Width = GridLength.Auto;
                    grid.ColumnDefinitions.Add(coldef);

                    RowDefinition rowdef = new RowDefinition();
                    rowdef.Height = GridLength.Auto;
                    grid.RowDefinitions.Add(rowdef);
                }
                grid.Background = new LinearGradientBrush(Colors.Gray, Colors.White,
                    new Point(0,0), new Point(1,1));

                Random rand = new Random();
                for (int i = 0; i < 25; i++)
                {
                    Button btn = new Button();
                    btn.FontSize = 12 + rand.Next(8);
                    btn.Content = "Button No. " + (i + 1);
                    btn.HorizontalAlignment = HorizontalAlignment.Center;
                    btn.VerticalAlignment = VerticalAlignment.Center;
                    btn.Margin = new Thickness(6);
                    grid.Children.Add(btn);
                    Grid.SetRow(btn, i%5);
                    Grid.SetColumn(btn, i/5);
                }

                grid.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                Size sizeGrid = grid.DesiredSize;
                Point ptGrid = new Point((dlg.PrintableAreaWidth - sizeGrid.Width)/2,
                    (dlg.PrintableAreaHeight - sizeGrid.Height)/2);
                grid.Arrange(new Rect(ptGrid, sizeGrid));

                dlg.PrintVisual(grid, Title);
            }
        }