Geometries

A Geometry is like the skeleton of a vector graphic, identifying the coordinates for drawing it.

CreateFlatGeometryButton is one place where you may leverage a geometry path; however, there are examples of this elsewhere, such as in the C# Hello World Demo. Therefore, here I will focus on CreateGeometryBrush, GetGeometryFromImage, and AddGeometry (within BeginComposite . . . EndComposite).

Usage Examples

In this example for CreateGeometryBrush, I set the Background of a TextBox to a GeometryBrush. This GeometryBrush creates a small light yellow rectangle surrounded by a thick Silver border:

TextBox txtBox = new TextBox();
txtBox.Width = 150D;
txtBox.Height = 39D;
txtBox.Margin = new Thickness(7, 5, 7, 5);
txtBox.Background = BrushExt.CreateGeometryBrush(Brushes.LightYellow, new Pen(){ Brush=Brushes.Silver, Thickness=.3 }, new RectangleGeometry(new Rect(1, 1, .9, .7)));

In this example for AddGeometry (to be called within BeginComposite . . . EndComposite), I add an Ellipse Geometry at row-column 13, 0 with a Silver Border and LightSlateGray Background. This Geometry subscribes to MouseSingleClickOnChild. Upon clicking on it, it will be rotated via a Transform. Note that the last parameter of AddGeometry is Image Width. This is because the GeometryDrawing is internally nested within a DrawingImage which is then placed in an empty Image. So, you are able to set the width of this image which is almost like a Canvas for the Geometry to reside on . . . For this reason, I also added a means to retrieve the Geometry from within the image via GetGeometryFromImage. See below:

.AddGeometry<Grid>(13, 0, Brushes.LightSlateGray, new Pen(){ Brush=Brushes.Silver, Thickness=5 }, new EllipseGeometry(){ RadiusX=55, RadiusY=35 }, 70)
.SubscribeMouseSingleClickOnChild<Image, Grid>(13, 0, (o, e) => { GeometryExt.GetGeometryFromImage(o).Transform = new RotateTransform() { Angle = rotateAngle }; rotateAngle = rotateAngle + 30; if (rotateAngle == 180) { rotateAngle = 0; } })

Last edited Mar 24, 2014 at 5:49 AM by stagathome0069, version 9

Comments

No comments yet.