How do I add text to a Line UIElement? I would like to have the text placed in the middle of the line.
<Line Stroke="Black" X1="{Binding From.CanvasCenterX}" Y1="{Binding From.CanvasCenterY}" X2="{Binding To.CanvasCenterX}" Y2="{Binding To.CanvasCenterY}" StrokeThickness="2" />
Is this possible?
You need to set X2 coordinate value based on length of Text for alignment.
The following XAML code adds text to a Line UIElement. In this example the text is presented by a
<TextBlock... />
. The text is centered at the Line, but this can easily be changed by theTextAlignment
property.VerticalAlignment
andHorizontalAlignment
places the<TextBlock../>
in the<Grid../>