Fill for EllipseGeometry - wpf

I need to have some drawing (triangle and circle) as one object (to set it as content). Triangle should be filled and circle shouldn't be filled with color. The problem is that EllipseGeometry doesn't have IsFilled property. If I remove Fill property at Path both wouldn't be filled. How can I have filled PathFigure and not filled Ellipse having them both in one Path parent?
<Path Stroke="#FFF633FF"
StrokeThickness="1"
Fill="#FFF633FF">
<Path.Data>
<GeometryGroup>
<EllipseGeometry Center="6,0"
RadiusX="4"
RadiusY="4">
</EllipseGeometry>
<PathGeometry >
<PathGeometry.Figures>
<PathFigure StartPoint="6,-15"
IsClosed="True">
<LineSegment Point="1,-25" />
<LineSegment Point="11,-25" />
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</GeometryGroup>
</Path.Data>
</Path>

A simple trick would be to replace the EllipseGeometry by a non-filled PathGeometry with two ArcSegments:
<PathGeometry >
<PathGeometry.Figures>
<PathFigure StartPoint="2,0" IsFilled="False">
<ArcSegment Point="10,0" Size="4,4" />
<ArcSegment Point="2,0" Size="4,4" />
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>

The whole point of a geometry is to describe a shape. Stroke and fill are always taken from the owning Path since the Path is responsible for drawing the shape. So what you're asking is not possible. You need to use two Paths here.

Related

Ellipse with CombinedGeometry

I have this ellipse:
<Ellipse Name="backgroundEllipse1" Fill="Pink">
<Ellipse.Clip>
<CombinedGeometry GeometryCombineMode="Exclude">
<CombinedGeometry.Geometry1>
<EllipseGeometry x:Name="backgroundEllipseMask1" Center="150,150" RadiusX="300" RadiusY="300"></EllipseGeometry>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<EllipseGeometry x:Name="backgroundEllipseMask2" Center="150,150" RadiusX="130" RadiusY="130"></EllipseGeometry>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</Ellipse.Clip>
</Ellipse>
How can I make something like this?
I'm trying to combine the center and Radius values but something escapes me.
You need an ArcSegment
<Canvas>
<Path Stroke="Pink" StrokeThickness="10" >
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="400,400">
<ArcSegment IsLargeArc="True"
Size="100, 100"
Point="480, 410"
SweepDirection="Counterclockwise" />
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
Note that the arc starts form (400,400) and ends in (480,410). It moves Counterclockwise and is a large arc. Size="100, 100" determines the size of the Ellipse (or Circle if they are equal) This post can help you.

WPF Callout Anchor start position

I have implement Callout control of Blend. Problem which I am facing is anchor point of the Callout starts with some margin from the top, While I want to have anchor from the top left of the callout.
Any help will be appreciated.
What I have now:
What I would like to have:
You seem to be mistaken about using this control. From MSDN, the Callout.AnchorPoint property Gets or sets the position of the callout relative to the top and left corner. It is used for positioning the control and does not alter the shape of the Callout.
UPDATE >>>
Dude!!! That's a really simple shape... just draw your own one with a Path... then you can make it any shape you want:
<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
<Path.Data>
<CombinedGeometry GeometryCombineMode="Union">
<CombinedGeometry.Geometry1>
<RectangleGeometry RadiusX="20" RadiusY="20" Rect="0,0,300,200">
<RectangleGeometry.Transform>
<TranslateTransform X="30" />
</RectangleGeometry.Transform>
</RectangleGeometry>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<PathGeometry>
<PathFigure StartPoint="0,30">
<LineSegment Point="50,10" />
<LineSegment Point="50,50" />
</PathFigure>
</PathGeometry>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</Path.Data>
<Path.Effect>
<DropShadowEffect Color="Black" Opacity="0.4" Direction="-135"
ShadowDepth="10" />
</Path.Effect>
</Path>

Drawing an arrow end on a Quadratic Bezier Segment using xaml

What's the easiest way to draw an arrow at the end of a QuadraticBezierSegment? The tricky part is to get the correct rotation to mach the incoming line segment.
Any ideas on how to go about this? Should I extend PathSegment?
I've got this for drawing a simple bezier line.
<Path Stroke="Black" StrokeThickness="1">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="100,430">
<PathFigure.Segments>
<PathSegmentCollection>
<QuadraticBezierSegment Point1="150,250" Point2="250,300" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
You could define the geometry for the arrow head....but it would take trial and error to correctly orientate it on the end of the bezier curve.
Instead you could use this control and define the endcap you wanted using geometry and it properly places it on the end of the "line".
http://blogs.msdn.com/b/mrochon/archive/2011/01/10/custom-line-caps-in-wpf.aspx
<loc:CappedLine Stroke="Red" StrokeThickness="1" Canvas.Left="40" Canvas.Top="200" RenderTransformOrigin="0.5,0.5" Height="107" Width="195">
<loc:CappedLine.EndCap>
<GeometryGroup>
<LineGeometry StartPoint="0,0" EndPoint="10,10"/>
<LineGeometry StartPoint="0,0" EndPoint="10,-10"/>
</GeometryGroup>
</loc:CappedLine.EndCap>
<loc:CappedLine.LinePath>
<PathGeometry Figures="M0,0 C1,1 10.5,75.5 48.5,66.5 86.5,57.5 5,3.5000146 105.5,16.500091 157.5,29.500166 164.5,87.500505 164.5,87.500505" />
</loc:CappedLine.LinePath>
</loc:CappedLine>
<loc:CappedLine Stroke="Red" StrokeThickness="1" Canvas.Left="180" Canvas.Top="200" RenderTransformOrigin="0.5,0.5" Height="107" Width="195">
<loc:CappedLine.EndCap>
<GeometryGroup>
<LineGeometry StartPoint="0,0" EndPoint="10,10"/>
<LineGeometry StartPoint="0,0" EndPoint="10,-10"/>
</GeometryGroup>
</loc:CappedLine.EndCap>
<loc:CappedLine.LinePath>
<PathGeometry Figures="M0,0 C1,1 10.5,75.5 48.5,66.5 86.5,57.5 5,3.5000146 105.5,16.500091" />
</loc:CappedLine.LinePath>
</loc:CappedLine>

Equivalent of IsFilled="false" for PathFigure in Path Mini-language (Silverlight/WPF)

I'm trying to find the equivalent of IsFilled="False" that is used in a PathGeometry, but for Path Mini.
You can see that the two paths below are identical, except for the one with geometries has IsFilled="False" in the second <PathGeometry>.<PathGeometry.Figures>.<PathFigure>. This is the desired behavior, but I'd like to have it for a Path Mini (i.e. in the first <Path>). I've looked through the documentation and can't seem to locate anything on it as it appears that Path Mini is not a collection of figures.
As I understand it, all shapes/geometries will get converted to path mini at run-time, so is there some way to reflect the compiled XAML to see how the interpreter renders the one with PathGeometry to Path Mini?
<Canvas Background="#FDB" Width="800" Height="600">
<!-- this is the LEFT-HAND Path in the picture above -->
<Path Canvas.Left="100" Canvas.Top="100"
Stroke="#385D8A" StrokeThickness="2" StrokeLineJoin="Round" Fill="#4F81BD"
Data="M0,0L102,0L102,102L0,102Z M46.15,49.01L-73.36,130.99L-96.42,-96.12L109.35,355.18">
</Path>
<!-- this is the RIGHT-HAND Path in the picture above -->
<Path Canvas.Left="300" Canvas.Top="100" Stroke="#385D8A" StrokeThickness="2" StrokeLineJoin="Round" Fill="#4F81BD">
<Path.Data>
<GeometryGroup>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="0,0" IsClosed="True">
<PathFigure.Segments>
<LineSegment Point="102,0" />
<LineSegment Point="102,102" />
<LineSegment Point="0,102" />
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure IsFilled="False" StartPoint="46.15,49.01">
<PathFigure.Segments>
<LineSegment Point="-73.36,130.99" />
<LineSegment Point="-96.42,-96.12" />
<LineSegment Point="109.35,355.18" />
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</GeometryGroup>
</Path.Data>
</Path>
</Canvas>
The path mini-lanuage only supports outlines so strokes must be converted to fills. This is straightforward to do yourself if you want one-pixel wide lines and you aren't too fussy about mitering or endcaps. Just use skinny rectangles. A true mathematical "grow" of an infinitely narrow stroke using the minimum number of points and handling crossings is quite a bit harder. However you might be able to use the WPF rendering engine to do that for you since obviously it can already do it.

Rotation and Direction of ArcSegment

Is there a way to get an ArcSegment to draw in a particular direction? As far as I can tell, it is always drawing top to bottom to top. For example, I have an ArcSegment which starts at 180 degrees (270 degrees is north) and draws an almost ellipse to 180 degrees. Right now, the drawing goes clockwise from....well, sorry, let me show you.
The left-hand one is the values I receive from a conversion set of values, but I need it to act like the right-hand one.
<Canvas Background="#FDB" Width="720" Height="540">
<Path Canvas.Left="100" Canvas.Top="100" Stroke="#385D8A" StrokeThickness="2" StrokeLineJoin="Round" Fill="#4F81BD">
<!-- this is the LEFT shape that I need drawn like the other one -->
<Path.Data>
<GeometryGroup>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="0,51" IsClosed="True">
<PathFigure.Segments>
<LineSegment Point="51,51" />
</PathFigure.Segments>
</PathFigure>
<PathFigure StartPoint="25.5,0">
<PathFigure.Segments>
<LineSegment Point="25.5,102" />
</PathFigure.Segments>
</PathFigure>
<PathFigure StartPoint="25.5,51" IsClosed="True" >
<PathFigure.Segments>
<ArcSegment Size="25.5,25.5" IsLargeArc="True" SweepDirection="Clockwise" Point="25.49,51" />
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</GeometryGroup>
</Path.Data>
</Path>
<Path Canvas.Left="200" Canvas.Top="100" Stroke="#385D8A" StrokeThickness="2" StrokeLineJoin="Round" Fill="#4F81BD">
<!-- this is the RIGHT shape, the way it should behave, but notice the different StartPoint and Point -->
<Path.Data>
<GeometryGroup>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="0,51" IsClosed="True">
<PathFigure.Segments>
<LineSegment Point="51,51" />
</PathFigure.Segments>
</PathFigure>
<PathFigure StartPoint="25.5,0">
<PathFigure.Segments>
<LineSegment Point="25.5,102" />
</PathFigure.Segments>
</PathFigure>
<PathFigure StartPoint="51,25.5" IsClosed="True" >
<PathFigure.Segments>
<ArcSegment Size="25.5,25.5" IsLargeArc="True" SweepDirection="Clockwise" Point="50.99,25.5" />
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</GeometryGroup>
</Path.Data>
</Path>
</Canvas>
I've tried toying around with RotationAngle, but that doesn't seem to have any effect as it works only with the X-axis, not Y-axis.
The first Path's values come from a conversion routine, so it's not that I can easily modify them.
I think I've figured it out - just make the Y-axis shorter instead of the X-axis. So:
<PathFigure StartPoint="51,25.5" IsClosed="True" >
<PathFigure.Segments>
<ArcSegment Point="50.99,25.5" Size="25.5,25.5" IsLargeArc="True" SweepDirection="Clockwise" />
</PathFigure.Segments>
</PathFigure>
should be:
<PathFigure StartPoint="51,25.5" IsClosed="True" >
<PathFigure.Segments>
<ArcSegment Point="51,24.99" Size="25.5,25.5" IsLargeArc="True" SweepDirection="Clockwise" />
</PathFigure.Segments>
</PathFigure>
As simple as that.

Resources