简体   繁体   中英

How to add a TextBlock within a Path?

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.

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM