Hossein Narimani Rad
Hossein Narimani Rad

Reputation: 32481

Draw styled lines in WPF

Is there any way to make lines between points, given a simple geometry as line style, using WPF geometries? I know it is possible to make these kind of lines:

-- -- --- --

But I want to make lines, using any simple geometry (e.g: the '^' symbol). So what I want is something like these: (the line may not necessarily be horizontal or vertical):

^^^^^^^^^^^^^^^^^    
*****************

Note: I don't want to make line with some characters. I want to do it using any arbitrary geometries (e.g: start shape, triangle, or any other geometry). In other word I want to repeat some geometries along a linear path between two points. So these simple geometries may be rotated somehow to follow the line and ...

Upvotes: 6

Views: 2283

Answers (2)

I think this is an interesting problem but I can't fit a satisfying answer in the stackoverflow textbox so I uploaded a proposed solution on github:

https://github.com/mrange/CodeStack/tree/master/q14545675/LineGeometry

I don't claim this is 100% solution to your problem (for one I am not 100% of all your requirements) but if you take a look at it perhaps something can be worked and improved upon.

Unless ofc I am way wrong on what you are looking for.

Upvotes: 1

Greg
Greg

Reputation: 11480

If I understand correctly, you'd like to use the * or ^ or ! as a line essentially. Rather then use a normal solid, dash, dotted, and so on line you'd like to use physical characters? But you'd like those characters to become a Geometry object.

You could do something like:

// Create a line of characters.
string lineString = "^^^^^^^^^^^^^^";

// Create Formatted Text, customize accordingly.
FormattedText formatText = new FormattedText(
     lineString, CultureInfo.GetCultureInfo("en-us"),
     FlowDirection.LeftToRight,
     new Typeface("Arial"), 32, Brushes.Black);

// Set the Width and Height.
formatText.MaxTextWidth = 200;
formatText.MaxTextHeight = 100;

// You can obviously add as many customization's and outputs of your choice.

Now I understand this isn't what you want, you want the above string to act in Geometry. To accomplish that; you just need to do:

// Build Geometry object to represent text.
Geometry lineGeometry = formatText.BuildGeometry(new System.Windows.Point(0, 0));

// Tailor Geometry object that represents our item.
Geometry hGeo = formatText.BuildHighlightGeometry(new System.Windows.Point(0, 0));

Now essentially you've built a Geometry object that represents "^^^^^^^^".

Hopefully I understood correctly, I don't know if that solves your problem.

Upvotes: 1

Related Questions