tags:

views:

17

answers:

2

Hi guys (and girls);

I was wondering if it was possible to do either in WPF:

Text on line, text on top of line

I guess the main problem here that I can't embed a textblock in a line in XAML, which is something I'm use to doing. Does anyone have any idea of how I can tackle this problem?

EDIT: It would also have to handle diagonal text.

+1  A: 

Could you have a three-column grid, with a line in the first and third column and the text in the second? Of course you’d have to set the left and right line’s properties so that they stretch across the entire width.

Timwi
I edited my post because you just reminded me of something- the lines would have to be diagonal too. I don't think your method would work in this case then, though it's a very, _very_ good idea I never even thought about.
DMan
+1  A: 

You can do this, this is actually pretty easy. You have to keep in mind that you can nest content inside a <TextBlock> tag....

<TextBlock>
    <Line X1="0" Y1="0" X2="100" Y2="0" Stroke="Black" StrokeThickness="4"/>
    <TextBlock Text="Hello there!" VerticalAlignment="Center" HorizontalAlignment="Center"/>
    <Line X1="0" Y1="0" X2="100" Y2="0" Stroke="Black" StrokeThickness="4"/>
</TextBlock>
Muad'Dib
Thank you! This worked perfectly! I'll work on making this more dynamic (IE- the line is always the same length even if there is more text) but it's a great starting point!
DMan
glad to help, I would make it a user control or custom control or something so you can make it easier to customize and get the exact effect you want
Muad'Dib
Thanks for the suggestion.
DMan