Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a TextBlock within a Path?

Tags:

c#

silverlight

I have a Silverlight app that adds a Path to the LayoutRoot grid of a UserControl. The path geometry is a simple rectangle.

I would like to be able to add a TextBlock that is contained within the Path that was added to the LayoutRoot grid.

I am also using a custom Adorner to allow me to resize the Path on the screen and move it around.

Basically, I want the TextBlock's parent to be the path, so that whenever I move the Path around, the TextBlock moves with it, and, also, the text within the TextBlock can never go outside the boundaries of the Path.

Here is an example of what I currently have:

var shape = new ShapeClass((o, u) => { LayoutRoot.Children.Add(o); LayoutRoot.Children.Add(u); }); 

Here is the constructor for the Shape class:

public ShapeClass(Action<Path, TextBlock> insert){}

Where 'o' is the Path object and 'u' is the TextBlock...

Does anyone have any ideas as to how this might be achieved?

Thanks.

like image 947
Chris Avatar asked Jan 12 '10 16:01

Chris


People also ask

How do you create type along a path?

Select the Text tool on the Tool bar. Place the Text tool on the path and click once. The mouse pointer will take on the Text I-beam shape and a flashing line will appear on the path along with small X. The small illustration below approximates what you will see.


2 Answers

Put both the path and the textbox into a Grid or canvas, and move that instead. That way the two controls will stay in the same position relative to each other.

like image 70
Guy Avatar answered Oct 13 '22 12:10

Guy


A Path is not a Content control hence you cannot place a TextBox within it.

If you are using a simple Rectangle then why not use a Border control instead?

like image 44
AnthonyWJones Avatar answered Oct 13 '22 11:10

AnthonyWJones