I have a path that maybe makes not much sense without some context, but I need it that way
<Path StrokeThickness="2" Stroke="Blue" >
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="-10000,20">
<BezierSegment Point1="100,100"
Point2="120,120"
Point3="350, 350" />
<BezierSegment Point1="400,400"
Point2="450, 450"
Point3="200, 600" />
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
I've noticed that when I have a long path UWP by default optimizes the draw, my path gets pixelated
I don't want this behavior, is there any way to disable it?
I really need a path like this, I can't change the length of it to get a better quality.
In WPF I get what I need:
The reason for why you get the Blurry Lines in your XAML is because that you have used this StartPoint="-10000,20". Our WinRT has an issue rendering large polylines when the Polyline has any two points that are more than 2048 pixels apart it scales the polyline rather than rendering it normally.
The following explaination is quoted from Brendan Clark - MSFT in this thread:
In WinRT the size of each shape is limited by the hardware you're running your app on. The lowest common denominator is 2048 x 2048. This is large enough that everything will look sharp as long as you keep each component of your UI at roughly the same scale as a typical screen. As soon as you try to draw things that are significantly larger than the screen, the shapes will be clamped to the maximum size supported on your hardware, and will be scaled up from that point to the size you requested. Since the shape is clamped to a lower resolution than what you requested, scaling it up causes it to look blurry.
So if you change the StartPoint="-10000,20" to StartPoint="100,20", you will see it work fine.
Based on your description, I know that you do not want to change your path data, the only way to workaround this issue is to manually clip the Polyline based on the size of the viewing area, for more information, please check this code sample.
I'm working on a small part of an application that requires us to draw shapes for the user to see. I'm using a path to display the shape, specifically binding a PathSegmentCollection to the PathGeometry.Figures like this --
<Path Name="Shape"
Stretch="Uniform"">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure IsClosed="True"
Segments="{Binding Segments}"
StartPoint="{Binding StartPoint}" />
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
Somewhere on that shape, a logo will be shown, but due to the variance in the shapes, I'm struggling to think of a solution where the logo text will always be shown on the shape (the shapes can be anything, even from a DXF file).
Here's an illustration of the problem --
The left image is what I have, but the right image is what I want.
Right now I'm drawing the logo as just a textblock on a grid that's bound to the size of the shape. I ended up going this route to keep the text automatically scaled to the correct height no matter the scaled units of the shape.
Ideally what I'd like to do is place a textblock inside a path, but I know that's not possible. I was wondering if anyone had any good ideas on how to align this text to the shape no matter what shapes come up.
In theory I'd like to be able to align it to all the regular orientations (top-left, top-center, bottom-right etc).
Thanks in advance!
I'm creating a speech bubble control for my application, and the way I'm looking to do it is to use a rectangle with rounded corners, then place a shape on top that forms the "origin" of the speech bubble. These are arranged in a Grid so that the bubble resizes to its content whilst keeping the origin shape constant (i.e. it won't stretch). Now, here's my question; is it possible to create a Path in WPF with one of the sides omitted (i.e. so the stroke is omitted from that edge, but the fill is still present)?
I know I could do it by placing 2 shapes on top of each other, but I'm looking for a solution that's as simple as possible!
Thanks, Lee.
Yes, it's possible. You just omit one of the edges. The Fill will still be applied inside the shape:
<Path Fill="Beige" Stroke="Black" Data="M 0,0 L 20,0 L 0,20"></Path>
Hi have the following piece of XAML
<Path Stroke="#FF000000" StrokeThickness="3" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeDashCap="Round" StrokeLineJoin="Round" StrokeMiterLimit="4" Name="kvg_0994c_s1">
<Path.Data>
<PathGeometry FillRule="Nonzero" Figures="M28.27,12.64C28.32,13.27 28.52,14.32 28.17,15.16 25.86,20.7 19.22,31.55 9.81,39.71" />
</Path.Data>
</Path>
I wish to animate the PathGemorty to reveal itself slowly (over 2 seconds or so). Basically the effect that I am after is drawing a line on the screen automatically, in particular the path that is specified in the code above.
I need to do this in C# code as I am loading the XAML dynamically from an external file. Any help would be greatly appreciated.
You must use WPF animation for it. Look here: http://msdn.microsoft.com/en-us/library/ms752312.aspx More information about animation you can find in excellent book "Windows Presentation Foundation Unleashed" by Adam Nathan.
I think you can find exact answer on your question here: http://social.msdn.microsoft.com/Forums/en/wpf/thread/19a7bd4b-cf28-4b31-a329-a5f58b9ec374
what do you mean by 'reveal itself slowly' ? You mean like it was drawn bit by bit ? Then you'll have to decompose the Data, then re-compose a geometry adding elements one by one. So you might, using the Path's name (kvg_0994c_s1) in code behind, (and assuming the Path.Data is always a PathGeometry, so you can cast it to PathGeometry) you get the PathGeometry.Figures in an initial List, then clear the figures in the displayed Path. Then you set-up a timer (a DispatchTimer might be enough) to call a function every 200ms or so and in this function you add one by one the figures to the PathGeometry.Figures of the displayed path. You might have to adjust both the number of parts you add each time, and timer values to get the effect you want. And if you want constant 'speed' -> you have to compute the length of each part and adjust. But it might be nice to have non-constant speed to look more like hand-drawing.
I'm trying to figure out how to completely fill a custom geometry. It seems like it should be a common question, but I haven't really been able to find any solutions.
I have the following example geometry:
<Path Fill="White" Stretch="Fill" Stroke="Black" StrokeThickness="2">
<Path.Data>
<PathGeometry
Figures="M112,296C112,296 136,296 136,320 M112,344C112,344 136,344 136,320 M112,296L112,296 96,296 96,344 112,344"/>
</Path.Data>
</Path>
Which produces the following result:
This is the result I would like to see:
Any Ideas? I know I could make a single arc and that would resolve this particular case, but in my application the user can draw any type of geometry so the result could be composed of any number of "primitives" (PolyLineSegments, EllipseGeometries, ArcSegments, etc) and in the case that the resultant geometry contains some type of closed area, I'd like to accurately fill that area.
EDIT:
Here is an example of what a CombinedGeometry looks like if I ensure all three adjacent geometries overlap and create a unioned CombinedGeometry with the following code:
<Path Grid.Row="2" Fill="White" Stretch="Fill" Stroke="Black" StrokeThickness="2">
<Path.Data>
<CombinedGeometry GeometryCombineMode="Union">
<CombinedGeometry.Geometry1>
<CombinedGeometry GeometryCombineMode="Union">
<CombinedGeometry.Geometry1>
<PathGeometry
Figures="M111,293C111,296 136,293 136,325"/>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<PathGeometry
Figures="M111,346C111,344 136,344 136,320"/>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<PathGeometry
Figures="M125,296L115,296 96,296 96,344 120,344"/>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</Path.Data>
</Path>
And here is the result:
I was hoping it would union just the strokes and automagically figure out the correct filling for the new contiguous polygon... bummer.
EDIT 2:
Hmm so I think I've come up with a couple possible solutions, neither of which are as easy as I was hoping they would be. The first option would be to combine all of the geometries as above using a CombineGeometry structure, then I called "GetFlattenedPathGeometry" on the resultant "CombineGeometry" in order to get a PathGeometry. Next I iterate over each Figure in the PathGeometry and just remove those which are holes (which I think you should be able to do by getting rid of all the figures which are entirely contained by another, or holes may follow a convention of having either clockwise or counter-clockwise coordinates, not sure..), if all goes well you should be left with a single fully filled geometry.
The second option would be to again call "GetFlattenedPathGeometry" on whatever the resultant path is, so as to get a vertex based polygonal approximation of the path (without all the curve, arc, ellipse, etc notation, we want a path containing only points and lines). After that, you would just combine all the resultant figures/segments into a single figure whose segments are ordered either clockwise or counter-clockwise.
I've tested both approaches and they seem to work with at least the simple test case outlined above, though they will not work with more complex shapes (self-intersecting, concave, etc).. support which I require.. so the question remains, how do I do this??
EDIT 3:
Here is a more complicated geometry in which ordering/combining becomes more difficult:
<Path Fill="White" Stretch="Fill" Stroke="Black" StrokeThickness="2">
<Path.Data>
<PathGeometry
Figures="M104,160C104,160 72,160 72,136
M104,128C104,128 72,128 72,152
M152,232L152,232 152,216 120,216 120,160 128,160
M152,232L152,232 72,232 104,216 104,160 96,160
M104,128L104,128 168,128
M128,160L128,160 168,160
M165,160L168,160 200,128
M200,160L200,160 200,128
M200,160L200,160 168,128 152,128"/>
</Path.Data>
</Path>
Which produces:
Your example geometry is a combination of three adjacent shapes which do not overlap. The stroke is drawn on the outside edges simply because the shapes are not closed and the inner stroke lines do not exist. Although it may appear that the shapes are being merged and the stroke is applied to the geometry as a whole, that is not what is happening.
Closing the hole becomes a more complex problem of programmatically detecting the hole and closing it with the appropriate shape or by creating a new combined shape which doesn't have the hole (possibly by detecting and tracing the outer points). I am not aware of any functionality in WPF which can help you with this task. There does exist a CombinedGeometry class which can produce a union of two overlapping shapes. The shapes in this example are not overlapping.
Without context, it is hard to recommend a solution. If this is a free form drawing program, perhaps the user simply has to draw another shape in the middle to close the geometry.
Treat it as a "connect the points" problem :)
You have 5 points:
96,296 - top left point (corner)
112,296 - top - start of bezier curve
136,320 - far right - end of first bezier curve, start of second one
112,344 - bottom - end of second bezier
96,344 - bottom left point (corner)
And now, we shall connect them.
<Path Fill="White" Stretch="Fill" Stroke="Black" StrokeThickness="2">
<Path.Data>
<PathGeometry Figures="M112,296 C112,296 136,296 136,320 C136,320 136,344 112,344 M112,344 96,344 96,296 112,296"/>
</Path.Data>
</Path>
You can also use <GeometryGroup FillRule="Nonzero" ...> to fill your custom path from 1st post. Default is FillRule="EvenOdd", which produces filling like yours.*
See Path Markup Syntax (http://msdn.microsoft.com/en-us/library/ms752293.aspx) for more information on path mini-language.
Changed <Path> to <GeometryGroup>
EDIT 1:
I reordered your path a bit:
<Path Fill="White" Stretch="Fill" Stroke="Black" StrokeThickness="2">
<Path.Data>
<PathGeometry Figures="M72,152 C72,152 72,128 104,128 L168,128 200,160 200,128 168,160 120,160 120,216 152,216 152,232 72,232 104,216 104,160 C104,160 72,160 72,136"/>
</Path.Data>
</Path>
Which gives us:
New shape
Drawing path is like using some kind of "draw shape" tool in vector editing software, where you have to select next points, and when you don't have next one - shape is automatically closed (last point is connected to first one, but just for the purpose of filling shape - we can see how it's done, when we look at the 'nose' of new shape).
In your example You have 9 separate shapes (each one in separate line, where M specifies start of new figure), and they are all filled in the said-above-way.
Ofcourse, you can use GeometryGroup (with FillRule) or CombinedGeometry (with CombinedGeometryMode) to connect shapes.
I found an interesting article about creating shapes with wpf using a svg-file created with a graphic-tool like inkscape. This might give you some insight.