protected override BitmapSource RenderFrame(DataRect dataRect, Rect output) { Grid grid = new Grid(); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); TextBlock lt = new TextBlock { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Text = String.Format("({0},{1})", dataRect.XMin, dataRect.YMax) }; grid.Children.Add(lt); Grid.SetRow(lt, 0); TextBlock rb = new TextBlock { VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right, Text = String.Format("({0},{1})", dataRect.XMax, dataRect.YMin) }; grid.Children.Add(rb); Grid.SetRow(rb, 1); Border border = new Border(); border.BorderThickness = new Thickness(3); border.BorderBrush = Brushes.Blue; border.Child = grid; RenderTargetBitmap rtb = new RenderTargetBitmap((int)output.Width, (int)output.Height, 96, 96, PixelFormats.Default); border.Measure(new Size(output.Width, output.Height)); border.Arrange(output); rtb.Render(border); Thread.Sleep(1000); return rtb; }
public SearchToolTipAdorner(UIElement adornedElement, DesignerView designerView, string text) : base(adornedElement) { this.scrollViewerToScreenDistance = designerView.ScrollViewer.PointToScreen(new Point(0, 0)).Y;; tooltip = new Border { Background = new SolidColorBrush(WorkflowDesignerColors.DesignerViewBackgroundColor), BorderBrush = new SolidColorBrush(WorkflowDesignerColors.WorkflowViewElementBorderColor), BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(4), Margin = new Thickness(10), Child = new TextBlock { Foreground = new SolidColorBrush(WorkflowDesignerColors.WorkflowViewElementCaptionColor), Margin = new Thickness(4, 0, 4, 0), MaxWidth = 300, Text = text, TextWrapping = TextWrapping.Wrap, TextTrimming = TextTrimming.CharacterEllipsis }, Effect = new DropShadowEffect { Color = Colors.Black, BlurRadius = 4, Opacity = 0.5 }, }; tooltip.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); }
public void BorderHitTestTest() { Border border = new Border { Width = 200, Height = 100, BorderThickness = new Thickness(10, 20, 30, 40), IsRootElement = true, }; border.Measure(Size.Infinity); border.Arrange(new Rect(border.DesiredSize)); BackgroundHitTestTest(border, null); BorderHitTestTest(border, null); border.Background = Brushes.Transparent; border.BorderBrush = null; BackgroundHitTestTest(border, border); BorderHitTestTest(border, border); border.Background = null; border.BorderBrush = Brushes.Transparent; BackgroundHitTestTest(border, null); BorderHitTestTest(border, border); border.Background = Brushes.Transparent; border.BorderBrush = Brushes.Transparent; BackgroundHitTestTest(border, border); BorderHitTestTest(border, border); }
public void ChildlessMeasureTest1 () { Border c = new Border (); Size s = new Size (10,10); c.Measure (s); Assert.AreEqual (new Size (0,0), c.DesiredSize, "DesiredSize"); }
public override DocumentPage GetPage(int pageNumber) { var page = _pages[pageNumber]; var container = new Border(); container.Padding = _margin; container.Child = page; container.Measure(PageSize); container.Arrange(new Rect(PageSize)); return new DocumentPage(container); }
public void ChildlessMeasureTest2 () { Border c = new Border (); Size s = new Size (10,10); c.Width = 20; c.Height = 20; c.Measure (s); Assert.AreEqual (new Size (10,10), c.DesiredSize, "DesiredSize"); }
public static BitmapSource GetThumbnailImage(this BitmapSource source, double percent, double dpiX, double dpiY) { double width = source.PixelWidth, height = source.PixelHeight; Algorithm.Math.ToPercentSize(percent, ref width, ref height); RenderTargetBitmap bmp = new RenderTargetBitmap((int)width, (int)height, dpiX, dpiY, PixelFormats.Pbgra32); Border image = new Border(); image.RenderSize = new Size(width, height); image.Background = new ImageBrush(source); image.Measure(new Size(width, height)); image.Arrange(new Rect(new Size(width, height))); bmp.Render(image); return BitmapFrame.Create(bmp); }
public void MeasureTest3 () { Border c = new Border (); Rectangle r = new Rectangle (); r.Width = 10; r.Height = 20; r.Measure (new Size (50, 50)); Assert.AreEqual (new Size (0, 0), r.DesiredSize); c.Child = r; c.Measure (new Size (50, 50)); Assert.AreEqual (new Size (10, 20), c.DesiredSize, "Border desired"); Assert.AreEqual (new Size (10, 20), r.DesiredSize, "Rectangle desired"); }
public void MouseDeviceButtonTest() { Border element = new Border { Background = Brushes.Transparent, Width = 100, Height = 100, IsRootElement = true }; element.Measure(Size.Infinity); element.Arrange(new Rect(element.DesiredSize)); int eventIndex = 0; int previewMouseDownIndex = 0; int previewMouseUpIndex = 0; int mouseDownIndex = 0; int mouseUpIndex = 0; element.PreviewMouseDown += (sender, e) => previewMouseDownIndex = ++eventIndex; element.PreviewMouseUp += (sender, e) => previewMouseUpIndex = ++eventIndex; element.MouseDown += (sender, e) => mouseDownIndex = ++eventIndex; element.MouseUp += (sender, e) => mouseUpIndex = ++eventIndex; TestPresentationSource presentationSource = new TestPresentationSource(); presentationSource.RootElement = element; MouseDevice mouseDevice = new MouseDevice(presentationSource); mouseDevice.Activate(); mouseDevice.ProcessRawEvent(new RawMouseButtonEventArgs(MouseButton.Left, MouseButtonState.Pressed, new Point(10, 10), 0)); Assert.AreEqual(MouseButtonState.Pressed, mouseDevice.GetButtonState(MouseButton.Left)); Assert.AreEqual(1, previewMouseDownIndex); Assert.AreEqual(2, mouseDownIndex); mouseDevice.ProcessRawEvent(new RawMouseButtonEventArgs(MouseButton.Left, MouseButtonState.Released, new Point(10, 10), 0)); Assert.AreEqual(MouseButtonState.Released, mouseDevice.GetButtonState(MouseButton.Left)); Assert.AreEqual(3, previewMouseUpIndex); Assert.AreEqual(4, mouseUpIndex); mouseDevice.ProcessRawEvent(new RawMouseButtonEventArgs(MouseButton.Left, MouseButtonState.Pressed, new Point(10, 10), 0)); Assert.AreEqual(MouseButtonState.Pressed, mouseDevice.GetButtonState(MouseButton.Left)); Assert.AreEqual(5, previewMouseDownIndex); Assert.AreEqual(6, mouseDownIndex); mouseDevice.Deactivate(); Assert.AreEqual(MouseButtonState.Released, mouseDevice.GetButtonState(MouseButton.Left)); Assert.AreEqual(7, previewMouseUpIndex); Assert.AreEqual(8, mouseUpIndex); }
public void MeasureRectangleBorderTest1_1 () { // This is the same as the above test but has Border b = new Border (); Path p = new Path (); b.Child = p; p.Fill = new SolidColorBrush (Colors.Black); RectangleGeometry r = new RectangleGeometry (); r.Rect = new Rect (10, 10, 20, 20); p.Data = r; b.Measure (new Size (50, 50)); b.Arrange (new Rect (0, 0, 50, 50)); Assert.AreEqual (new Size (30,30), b.DesiredSize, "b desired"); Assert.AreEqual (new Size (30,30), p.DesiredSize, "p desired"); Assert.AreEqual (new Size (50,50), b.RenderSize, "b RenderSize"); Assert.AreEqual (new Size (50,50), p.RenderSize, "p RenderSize"); }
public void MeasureRectangleBorderTest1 () { // See 1_1 1_2 for demonstation of this as a measure invalidation bug. Border b = new Border (); Path p = new Path (); p.Fill = new SolidColorBrush (Colors.Black); RectangleGeometry r = new RectangleGeometry (); r.Rect = new Rect (10, 10, 20, 20); p.Data = r; b.Child = p; b.Measure (new Size (50, 50)); b.Arrange (new Rect (0, 0, 50, 50)); Assert.AreEqual (new Size (0,0), b.DesiredSize, "b desired"); Assert.AreEqual (new Size (50,50), b.RenderSize, "b RenderSize"); Assert.AreEqual (new Size (0,0), p.DesiredSize, "p DesiredSize"); Assert.AreEqual (new Size (50,50), p.RenderSize, "p RenderSize"); }
public void MeasureTest2_1 () { Border b = new Border (); Canvas c = new Canvas (); Rectangle r = new Rectangle (); r.Width = 10; r.Height = 20; r.Measure (new Size (50, 50)); Assert.AreEqual (new Size (0, 0), r.DesiredSize); b.Child = c; c.Children.Add (r); b.Width = 20; b.Height = 10; b.Measure (new Size (50, 50)); Assert.AreEqual (new Size (0, 0), c.DesiredSize, "Canvas desired"); Assert.AreEqual (new Size (0, 0), r.DesiredSize, "Rectangle desired"); Assert.AreEqual (new Size (20, 10), b.DesiredSize, "Border desired"); }
public void BorderRenderTest() { Brush backgroundBrush = new LinearGradientBrush(30, Colors.Blue, Colors.Green); Brush borderBrush = new LinearGradientBrush(-30, Colors.Red, Colors.Blue); Thickness borderThickness = new Thickness(10, 20, 30, 40); Border border = new Border { Child = new FrameworkElement { Width = 200, Height = 100 }, Background = backgroundBrush, BorderBrush = borderBrush, BorderThickness = borderThickness, }; border.Measure(Size.Infinity); border.Arrange(new Rect(border.DesiredSize)); IRenderElementFactory factory = TestRenderElementFactory.Default; border.GetRenderElement(factory); Assert.AreEqual(new Rect(240, 160), border.GetRenderElement(factory).Bounds); Assert.AreEqual(2, border.GetRenderElement(factory).Children.Count()); IBorderRenderElement borderRenderElement = border.GetRenderElement(factory).Children.ElementAt(0) as IBorderRenderElement; Assert.IsNotNull(borderRenderElement); Assert.AreEqual(backgroundBrush, borderRenderElement.Background); Assert.AreEqual(borderBrush, borderRenderElement.BorderBrush); Assert.AreEqual(borderThickness, borderRenderElement.BorderThickness); Assert.AreEqual(new Rect(240, 160), borderRenderElement.Bounds); IVisualRenderElement visualRenderElement = border.GetRenderElement(factory).Children.ElementAt(1) as IVisualRenderElement; Assert.IsNotNull(visualRenderElement); Assert.AreEqual(new Rect(10, 20, 200, 100), visualRenderElement.Bounds); border.Child = null; Assert.AreEqual(1, border.GetRenderElement(factory).Children.Count()); }
protected override void OnRender(DrawingContext drawingContext) { Transform transform = isTextRightToLeft ? new MatrixTransform(-1, 0, 0, 1, 0, 0) : Transform.Identity; Border tooltip = new Border { Background = new SolidColorBrush(Colors.White), BorderBrush = new SolidColorBrush(WorkflowDesignerColors.WorkflowViewElementBorderColor), BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(4), Margin = new Thickness(10), Child = new TextBlock { Margin = new Thickness(4, 0, 4, 0), MaxHeight = 100, Text = expressionString, }, Effect = new DropShadowEffect { Color = Colors.Black, BlurRadius = 4, Opacity = 0.5 }, RenderTransform = transform }; tooltip.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); VisualBrush brush = new VisualBrush() { Visual = tooltip }; Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize); Rect tooltipRect = new Rect(adornedElementRect.TopLeft + new Vector(adornedElementRect.Width, -tooltip.DesiredSize.Height), tooltip.DesiredSize); Pen renderPen = new Pen(); drawingContext.DrawRectangle(brush, renderPen, tooltipRect); }
void UpdateShadow() { if (substance == null) return; if (style == null) return; Thread.Sleep(300); // Black material DiffuseMaterial material = new DiffuseMaterial(Brushes.Black); material.Freeze(); // Create molecules ModelVisual3D container = new ModelVisual3D(); foreach (Data.Molecule molecule in substance.Molecules) { foreach (Data.Atom atom in molecule.Atoms) { if (style.ColorStyle.ColorScheme[atom.Element].Diffuse.A < 5) continue; Sphere sphere = new Sphere(); sphere.Material = material; sphere.Radius = Atom.GetAtomRadius(atom, style.GeometryStyle); sphere.Center = atom.Position; container.Children.Add(sphere); } double bondRadius = Bond.GetBondRadius(style.GeometryStyle); foreach (Data.Bond bond in molecule.Bonds) { if (style.ColorStyle.UseSingleBondMaterial) { if (style.ColorStyle.BondMaterial.Diffuse.A < 5) continue; } else if (style.ColorStyle.ColorScheme[bond.Begin.Element].Diffuse.A < 5 || style.ColorStyle.ColorScheme[bond.End.Element].Diffuse.A < 5) continue; Cylinder cylinder = new Cylinder(bond.Begin.Position, bond.End.Position, bondRadius); cylinder.Material = material; container.Children.Add(cylinder); } #region Build approximation of ribbon double radius = 0.45; foreach (Data.Chain chain in molecule.Chains) { for (int i = 0; i < chain.Residues.Count; i++) { if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Helix) if (style.GeometryStyle.HelixHeight < 0.05 || style.GeometryStyle.HelixWidth < 0.05) continue; else radius = Residue.HelixWidth * ((style.GeometryStyle.HelixHeight + style.GeometryStyle.HelixWidth) / 2.0); if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Sheet) if (style.GeometryStyle.SheetHeight < 0.05 || style.GeometryStyle.SheetWidth < 0.05) continue; else radius = Residue.SheetWidth * ((style.GeometryStyle.SheetHeight + style.GeometryStyle.SheetWidth) / 2.0); if (chain.Residues[i].GetStructureType() == SecondaryStructureType.NotDefined) if (style.GeometryStyle.TurnHeight < 0.05 || style.GeometryStyle.TurnWidth < 0.05) continue; else radius = Residue.TurnWidth * ((style.GeometryStyle.TurnHeight + style.GeometryStyle.TurnWidth) / 2.0); if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Helix && style.ColorStyle.HelixMaterial.Diffuse.A < 5) continue; if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Sheet && style.ColorStyle.SheetMaterial.Diffuse.A < 5) continue; if (chain.Residues[i].GetStructureType() == SecondaryStructureType.NotDefined && style.ColorStyle.TurnMaterial.Diffuse.A < 5) continue; Data.Atom alfaCarbon = chain.Residues[i].AlfaCarbon; if (alfaCarbon != null) { Point3D begin = alfaCarbon.Position; alfaCarbon = null; for (int j = i + 1; j < chain.Residues.Count; j++) { alfaCarbon = chain.Residues[j].AlfaCarbon; if (alfaCarbon != null) break; } if (alfaCarbon != null) { Point3D end = alfaCarbon.Position; Cylinder cylinder = new Cylinder(begin, end, radius); container.Children.Add(cylinder); } } } } #endregion } // Get bounding box Rect3D boundingBox = VisualTreeHelper.GetDescendantBounds(container); if (boundingBox.IsEmpty) { shadowRefreshStarted = false; return; } #region Render Shadow const double blurSize = 25; const int renderTargetWidth = 200; int renderTargetHeight = (int)(200.0 * (boundingBox.SizeX / boundingBox.SizeY)); RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(renderTargetWidth, renderTargetHeight, 96, 96, PixelFormats.Pbgra32); Viewport3D shadowViewport3D = new Viewport3D(); Border border = new Border(); border.Padding = new Thickness(blurSize); border.Child = shadowViewport3D; // Change size of the visualizer border.Width = renderTargetBitmap.PixelWidth; border.Height = renderTargetBitmap.PixelHeight; border.Measure(new Size(renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight)); border.Arrange(new Rect(0, 0, renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight)); shadowViewport3D.Children.Add(container); // Create camera OrthographicCamera orthographicCamera = new OrthographicCamera(); #region Accomodate camera to fit content orthographicCamera.Position = new Point3D(boundingBox.Location.X + boundingBox.SizeX / 2.0, boundingBox.Location.Y, boundingBox.Location.Z + boundingBox.SizeZ / 2.0); orthographicCamera.LookDirection = new Vector3D(0, 1, 0); orthographicCamera.UpDirection = new Vector3D(-1, 0, 0); orthographicCamera.Width = boundingBox.SizeZ; #endregion orthographicCamera.NearPlaneDistance = 0; // Set the camera & correct lights shadowViewport3D.Camera = orthographicCamera; BlurEffect blurEffect = new BlurEffect(); blurEffect.Radius = blurSize; border.Effect = blurEffect; renderTargetBitmap.Render(border); renderTargetBitmap.Freeze(); #endregion // Invoke in main thread Dispatcher.BeginInvoke((Action) delegate { #region Create Plane Vector3D margin = new Vector3D(boundingBox.SizeX * 0.4, 0, boundingBox.SizeZ * 0.4); Point3D[] points = new Point3D[] { boundingBox.Location + new Vector3D(-margin.X, -margin.Y, -margin.Z), boundingBox.Location + new Vector3D(margin.X + boundingBox.SizeX, -margin.Y, -margin.Z), boundingBox.Location + new Vector3D(margin.X + boundingBox.SizeX, -margin.Y, margin.Z + boundingBox.SizeZ), boundingBox.Location + new Vector3D(-margin.X, -margin.Y, margin.Z + boundingBox.SizeZ) }; Polygon shadowPlane = new Polygon(); shadowPlane.Positions = points; shadowPlane.TextureCoordinates = new Point[] { new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0) }; #endregion shadowBrush.ImageSource = renderTargetBitmap; shadowBrush.Stretch = Stretch.Fill; shadowTargetOpacity = 0.8; shadowPlane.Material = new DiffuseMaterial(shadowBrush); shadowContainer.Children.Clear(); shadowContainer.Children.Add(shadowPlane); // Update shadow hash shadowRefreshStarted = false; }, DispatcherPriority.SystemIdle); }
public void LayoutMarginTest () { Border b = new Border (); var stack = new StackPanel (); stack.Children.Add (CreateSlotItem ()); stack.Children.Add (CreateSlotItem ()); stack.Children.Add (CreateSlotItem ()); stack.HorizontalAlignment = HorizontalAlignment.Right; b.Width = 50; b.Child = stack; stack.Margin = new Thickness (10,20,0,0); b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height)); Assert.AreEqual (new Rect (0,0,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString ()); Assert.AreEqual (new Rect (0,33,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString ()); Assert.AreEqual (new Rect (0,66,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString ()); Assert.AreEqual (new Rect (0,0,50,119).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString (), "stack"); Assert.AreEqual (new Rect (0,0,50,119).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)b).ToString (), "border"); Assert.AreEqual (new Size (50,119),b.DesiredSize); Assert.AreEqual (new Size (35,119),stack.DesiredSize); }
public void LayoutSlotTest4InTree () { Border b = new Border (); var stack = new StackPanel (); var panel = new Grid (); panel.Children.Add (b); panel.Background = new SolidColorBrush (Colors.Green); stack.Children.Add (CreateSlotItem ()); stack.Children.Add (CreateSlotItem ()); stack.Children.Add (CreateSlotItem ()); stack.HorizontalAlignment = HorizontalAlignment.Right; b.Width = 50; b.Child = stack; b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); Assert.AreEqual (new Size (0,0), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual"); b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height)); Assert.AreEqual (new Rect (0,0,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString (), "slot0"); Assert.AreEqual (new Rect (0,33,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString (), "slot1"); Assert.AreEqual (new Rect (0,66,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString (), "slot2"); Assert.AreEqual (new Rect (0,0,50,99).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString ()); Assert.AreEqual (new Rect (0,0,50,99).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)b).ToString ()); Assert.AreEqual (new Size (50,99),b.DesiredSize); Assert.AreEqual (new Size (25,99),stack.DesiredSize); Assert.AreEqual (new Size (25,99), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual"); TestPanel.Children.Add (panel); Assert.AreEqual (new Size (0,0),b.DesiredSize); Assert.AreEqual (new Size (0,0),stack.DesiredSize); b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); Assert.AreEqual (new Size (0,0), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual"); b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height)); Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString (), "slot0 in tree"); Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString (), "slot1 in tree"); Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString (), "slot2 in tree"); Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString ()); Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)b).ToString ()); Assert.AreEqual (new Size (50,99),b.DesiredSize); Assert.AreEqual (new Size (25,99),stack.DesiredSize); TestPanel.Children.Remove (panel); CreateAsyncTest (panel, () => { Assert.AreEqual (new Rect (0,0,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString (), "slot0"); Assert.AreEqual (new Rect (0,33,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString (), "slot1"); Assert.AreEqual (new Rect (0,66,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString (), "slot2"); Assert.AreEqual (new Rect (0,0,50,TestPanel.ActualHeight).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString (), "slot3"); Assert.AreEqual(new Rect(0, 0, TestPanel.ActualWidth, TestPanel.ActualHeight).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)b).ToString(), "slot4"); Assert.AreEqual (new Size (50,99),b.DesiredSize, "b desired async"); Assert.AreEqual (new Size (25,99),stack.DesiredSize, "stack desired async"); }); }
public void AlignmentTest3 () { Border b = new Border (); var stack = new StackPanel (); stack.Children.Add (new Border ()); stack.Children.Add (new Border ()); stack.Children.Add (new Border ()); stack.HorizontalAlignment = HorizontalAlignment.Right; b.Width = 50; stack.Width = 50; b.Child = stack; b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height)); Assert.AreEqual (new Rect (0,0,50,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString (), "child 0"); Assert.AreEqual (new Rect (0,0,50,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString (), "child 1"); Assert.AreEqual (new Rect (0,0,50,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString (), "child 2"); Assert.AreEqual (new Rect (0,0,50,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString (), "stack slot"); Assert.AreEqual (new Rect (0,0,50,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)b).ToString (), "b slot"); Assert.AreEqual (new Size (0,0), stack.Children[0].DesiredSize, "child 0 desired"); Assert.AreEqual (new Size (50,0),b.DesiredSize, "b desired"); Assert.AreEqual (new Size (50,0),stack.DesiredSize, "stack desired"); }
public void ArrangeTooLongLocal_LineWrapMeasureReverseTest () { Border b = new Border (); TextBlock tb = new TextBlock (); tb.TextWrapping = TextWrapping.Wrap; b.Child = tb; tb.Width = 44; tb.Text = "Hello and don't you forget Who I am"; Assert.IsTrue (tb.ActualWidth > 32 && tb.ActualWidth < 34, "1. textblock.ActualWidth is " + tb.ActualWidth.ToString ()); Assert.AreEqual (7, GetLineCount (tb.ActualHeight), "1. line count based on textblock.ActualHeight"); //Assert.AreEqual (112, tb.ActualHeight, "1. tb.ActualHeight"); //Console.WriteLine ("=========== Calling Border.Measure() ============"); b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); //Console.WriteLine ("========= Done calling Border.Measure() ========="); // FIXME: wrong after this point Assert.IsTrue (tb.ActualWidth < 10.9 && tb.ActualWidth > 10.8, "2. textblock.ActualWidth is " + tb.ActualWidth.ToString ()); Assert.AreEqual (28, GetLineCount (tb.ActualHeight), "2. line count based on textblock.ActualHeight"); //Assert.AreEqual (560, tb.ActualHeight, "2. tb.ActualHeight"); tb.Text = "Hello and don't you forget Who I am."; Assert.IsTrue (tb.ActualWidth < 10.9 && tb.ActualWidth > 10.8, "3. textblock.ActualWidth is " + tb.ActualWidth.ToString ()); Assert.AreEqual (29, GetLineCount (tb.ActualHeight), "3. line count based on textblock.ActualHeight"); //Assert.AreEqual (576, tb.ActualHeight, "3. tb.ActualHeight"); tb.Width = 70; b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); Assert.IsTrue (tb.ActualWidth < 10.9 && tb.ActualWidth > 10.8, "4. textblock.ActualWidth is " + tb.ActualWidth.ToString ()); Assert.AreEqual (29, GetLineCount (tb.ActualHeight), "4. line count based on textblock.ActualHeight"); //Assert.AreEqual (576, tb.ActualHeight, "4. tb.ActualHeight"); b.InvalidateMeasure (); tb.InvalidateMeasure (); b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); Assert.IsTrue (tb.ActualWidth < 10.9 && tb.ActualWidth > 10.8, "5. textblock.ActualWidth is " + tb.ActualWidth.ToString ()); Assert.AreEqual (29, GetLineCount (tb.ActualHeight), "5. line count based on textblock.ActualHeight"); //Assert.AreEqual (576, tb.ActualHeight, "5. tb.ActualHeight"); }
public void LayoutSlotTest2 () { Border b = new Border (); var stack = new StackPanel (); stack.Children.Add (CreateSlotItem ()); stack.Children.Add (CreateSlotItem ()); stack.Children.Add (CreateSlotItem ()); b.Width = 50; b.Height = 300; b.Child = stack; b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height)); Assert.AreEqual (new Rect (0,0,50,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0])); Assert.AreEqual (new Rect (0,33,50,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1])); Assert.AreEqual (new Rect (0,66,50,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2])); Assert.AreEqual (new Size (50,300),b.DesiredSize); Assert.AreEqual (new Size (50,300),b.RenderSize); }
public void ArrangeTooLongLineWrapMeasureReverseTest () { Border b = new Border (); TextBlock tb = new TextBlock (); tb.TextWrapping = TextWrapping.Wrap; b.Child = tb; b.Width = 44; tb.Text = "Hello and don't you forget Who I am"; Assert.IsTrue (tb.ActualWidth > 192.8 && tb.ActualWidth < 202.4, "1. textblock.ActualWidth is " + tb.ActualWidth.ToString ()); Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "1. line count based on textblock.ActualHeight"); //Assert.AreEqual (16, tb.ActualHeight, "tb.ActualHeight"); //Console.WriteLine ("=========== Calling Border.Measure() ============"); b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); //Console.WriteLine ("========= Done calling Border.Measure() ========="); // FIXME: wrong after this point // // Debug output: // // =========== Calling Border.Measure() ============ // TextBlock::MeasureOverride(availableSize = { 44.000000, inf }) // TextBlock::Layout(constraint = { 44.000000, inf }) => 32.403809, 118.317073 // ========= Done calling Border.Measure() ========= // // Seems to me that the resulting ActualWidth/Height are correct, so what // exactly is Silverlight doing here? // note: need to fix ActualWidth values to be within moonlight's tolerance Assert.IsTrue (tb.ActualWidth < 10.9 && tb.ActualWidth > 10.8, "2. textblock.ActualWidth is " + tb.ActualWidth.ToString ()); Assert.AreEqual (28, GetLineCount (tb.ActualHeight), "2. line count based on textblock.ActualHeight"); //Assert.AreEqual (560, tb.ActualHeight, "tb.ActualHeight1"); }
public void ArrangeTooLongLineTest () { Border b = new Border (); TextBlock tb = new TextBlock (); tb.Text = "Hello and don't you forget Who I am"; b.Child = tb; b.Width = 44; Assert.IsTrue (tb.ActualWidth > 192.8 && tb.ActualWidth < 202.4, "1. textblock.ActualWidth is " + tb.ActualWidth.ToString ()); Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "1. line count based on textblock.ActualHeight"); //Assert.IsTrue (tb.ActualWidth < 202.4 && tb.ActualWidth > 202.3, "1. tb.ActualWidth is " + tb.ActualWidth.ToString ()); //Assert.AreEqual (16, tb.ActualHeight, "1. tb.ActualHeight"); b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); Assert.IsTrue (tb.ActualWidth > 192.8 && tb.ActualWidth < 202.4, "2. textblock.ActualWidth is " + tb.ActualWidth.ToString ()); Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "2. line count based on textblock.ActualHeight"); Assert.AreEqual (1, GetLineCount (tb.DesiredSize.Height), "2. line count based on textblock.DesiredSize"); Assert.AreEqual (1, GetLineCount (b.DesiredSize.Height), "2. line count based on border.DesiredSize"); //Assert.AreEqual (new Size (44,16), tb.DesiredSize, "2. tb.DesiredSize"); //Assert.AreEqual (new Size (44,16), b.DesiredSize, "2. b.DesiredSize"); //Assert.IsTrue (tb.ActualWidth < 202.4 && tb.ActualWidth > 202.3, "2. tb.ActualWidth is " + tb.ActualWidth.ToString ()); //Assert.AreEqual (16, tb.ActualHeight, "2. tb.ActualHeight"); b.Arrange (new Rect (0,0, b.DesiredSize.Width, b.DesiredSize.Height)); Assert.IsTrue (tb.ActualWidth > 192.8 && tb.ActualWidth < 202.4, "3. tb.ActualWidth is " + tb.ActualWidth.ToString ()); Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "3. line count based on textblock.ActualHeight"); Assert.AreEqual (1, GetLineCount (tb.DesiredSize.Height), "3. line count based on textblock.DesiredSize"); Assert.AreEqual (1, GetLineCount (b.ActualHeight), "3. line count based on border.ActualHeight"); Assert.AreEqual (1, GetLineCount (b.DesiredSize.Height), "3. line count based on border.DesiredSize"); //Assert.AreEqual (new Size (44,16), tb.DesiredSize, "3. tb.DesiredSize"); //Assert.AreEqual (new Size (44,16), b.DesiredSize, "3. b.DesiredSize"); //Assert.IsTrue (tb.ActualWidth > 202.3 && tb.ActualWidth < 202.4,"3. tb.ActualWidth is " + tb.ActualWidth.ToString ()); //Assert.AreEqual (16, tb.ActualHeight, "3. tb.ActualHeight"); //Assert.AreEqual (new Size (44,16), new Size (b.ActualWidth, b.ActualHeight), "3. b.Actual*"); }
public void ComputeActualWidthBorderMeasure () { Border b = new Border (); Canvas c = new Canvas (); b.Child = c; Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired1"); Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual1"); Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot"); c.MaxWidth = 25; c.Width = 50; c.MinHeight = 33; Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired2"); Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual2"); Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot"); b.Measure (new Size (100, 100)); Assert.AreEqual (new Size (25,33), c.DesiredSize, "c desired3"); Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual3"); Assert.IsTrue (c.UseLayoutRounding, "use rounding"); }
public static FrameworkElement GetRendreable(IconVm iconVm, ImageSource sourceIcon, Color color) { var border = new Border() { Background = new SolidColorBrush(color), Width = iconVm.Width, Height = iconVm.Height }; var image = new Image() { Stretch = Stretch.Uniform, Source = sourceIcon, Width = iconVm.ImageWidth, Height = iconVm.ImageHeight, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; border.Child = image; border.Measure(new Size(border.Width, border.Height)); border.Arrange(new Rect(new Size(border.Width, border.Height))); border.UpdateLayout(); return border; }
public void ExpandInArrange_OutsideTree_BorderParent_FixedSize () { // We always expand star rows if we're not in the live tree var parent = new Border (); // Measure with infinity and check results. MyGrid grid = new MyGrid { Width = 200, Height = 200 }; grid.AddRows (Star); grid.AddColumns (Star); grid.AddChild (ContentControlWithChild (), 0, 0, 1, 1); parent.Child = grid; parent.InvalidateSubtree (); parent.Measure (Infinity); grid.CheckMeasureArgs ("#1", new Size (200, 200)); grid.CheckMeasureResult ("#2", new Size (50, 50)); Assert.AreEqual (new Size (200, 200), 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, 1000, 10000)); 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, 5, 5)); grid.CheckMeasureArgs ("#8"); // No re-measuring grid.CheckArrangeArgs ("#9"); // No re-arranging grid.CheckArrangeResult ("#10"); grid.CheckRowHeights ("#11", 200); grid.CheckColWidths ("#12", 200); // If we measure with a finite size, the rows/cols still expand // to consume the available space grid.Reset (); parent.InvalidateSubtree (); parent.Measure (new Size (1000, 1000)); grid.CheckMeasureArgs ("#13", new Size (200, 200)); grid.CheckMeasureResult ("#14", new Size (50, 50)); Assert.AreEqual (new Size (200, 200), 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); }
public void BackgroundTest2 () { Border b = new Border (); Canvas c = new Canvas (); c.Background = new SolidColorBrush (Colors.Orange); b.Child = c; c.Width = 50; c.Height = 50; b.Measure (new Size (100,100)); Assert.AreEqual (new Size (50,50), c.DesiredSize, "c desired"); Assert.AreEqual (new Size (50,50), b.DesiredSize, "b desired"); Assert.AreEqual (HorizontalAlignment.Stretch, c.HorizontalAlignment); Assert.AreEqual (VerticalAlignment.Stretch, c.VerticalAlignment); }
//[MoonlightBug ("Extents are slightly off (27,17) instead of (28,16), likely due to font metrics")] public void MeasureTest () { Border b = new Border (); TextBlock tb = new TextBlock (); tb.Text = "Hello"; b.Child = tb; b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "line count based on tb.ActualHeight"); Assert.AreEqual (1, GetLineCount (tb.DesiredSize.Height), "line count based on tb.DesiredSize"); //Assert.AreEqual (new Size (28,16), tb.DesiredSize, "tb.DesiredSize"); }
private static object PrepareInfoContent(StackPanel dataPointsInfoPanel) { Border border = new Border(); border.Child = dataPointsInfoPanel; border.Background = new SolidColorBrush(Colors.White); border.BorderBrush = new SolidColorBrush(Colors.Black); border.BorderThickness = new Thickness(1); border.CornerRadius = new CornerRadius(4); border.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); border.DataContextChanged += Border_DataContextChanged; return border; }
//[MoonlightBug ("Extents are slightly off (44,17) instead of (44,16), likely due to font metrics")] public void MeasureTooLongLineTest () { Border b = new Border (); TextBlock tb = new TextBlock (); tb.Text = "Hello and don't you forget Who I am"; b.Child = tb; b.Width = 44; b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "line count based on tb.ActualHeight"); Assert.AreEqual (1, GetLineCount (tb.DesiredSize.Height), "line count based on tb.DesiredSize"); //Assert.AreEqual (new Size (44,16), tb.DesiredSize, "tb.DesiredSize"); }
protected override Size MeasureOverride(Size constraint) { border.Measure(AdornedElement.RenderSize); return(border.DesiredSize); }
public void MeasureTooLongLineWrapTest () { Border b = new Border (); TextBlock tb = new TextBlock (); tb.Text = "Hello and don't you forget Who I am"; tb.TextWrapping = TextWrapping.Wrap; b.Child = tb; b.Width = 44; b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity)); Assert.IsTrue (tb.ActualWidth > 10.8 && tb.ActualWidth < 10.9, "textblock.ActualWidth is " + tb.ActualWidth.ToString ()); Assert.AreEqual (28, GetLineCount (tb.ActualHeight), "line count based on tb.ActualHeight"); Assert.AreEqual (34, tb.DesiredSize.Width, "textblock.DesiredSize.Width is " + tb.DesiredSize.Width.ToString ()); Assert.AreEqual (7, GetLineCount (tb.DesiredSize.Height), "line count based on tb.DesiredSize"); //Assert.AreEqual (new Size (33,112), tb.DesiredSize, "tb.DesiredSize"); }