I am trying to create a red circle with black x through it using XAML.
My problem is that they are not aligned correctly.
What is the right way to do this?
This is what I have so far:
<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Image> <Image.Source> <DrawingImage> <DrawingImage.Drawing> <DrawingGroup> <GeometryDrawing Brush="Red"> <GeometryDrawing.Pen> <Pen Brush="Transparent" Thickness="0"/> </GeometryDrawing.Pen> <GeometryDrawing.Geometry> <EllipseGeometry Center="8,8" RadiusX="8" RadiusY="8"/> </GeometryDrawing.Geometry> </GeometryDrawing> <GeometryDrawing> <GeometryDrawing.Pen> <Pen Brush="Black" Thickness="2.5"/> </GeometryDrawing.Pen> <GeometryDrawing.Geometry> <PathGeometry> <PathFigure StartPoint="4,4"> <LineSegment Point="12,12"/> </PathFigure> <PathFigure StartPoint="4,12"> <LineSegment Point="12,4"/> </PathFigure> </PathGeometry> </GeometryDrawing.Geometry> </GeometryDrawing> </DrawingGroup> </DrawingImage.Drawing> </DrawingImage> </Image.Source> </Image> </Grid>
Just placing the ellipse in the same grid with black X, X is not completely focused on the ellipse, because the coordinates of each line that you draw are really the coordinates in the space allocated for it.
I think they had to be in some kind of geometry or draw an aggregate to give them the same coordinate system. The geometry group and path are aggregators, but both require that their contents have the same fill and stroke, and the stroke and fill are different for the red circle (no stroke) and black X (no fill).
The only aggregator that gives common coordinate systems and allows for various fills and strokes for its members that I could find is a DrawingGroup.
The line labels that work to create the Path property through their Data don't seem to work to create the PathGeometry, so everything had to be filled out manually.
source share