Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add text inside a shape in XAML

I am working on a Metro App using C++ and XAML. I want to create a polygon shape and add text inside it.

At first I thought of defining my own Controltemplate and apply it to Textblock but unfortunately it does not understand TargetType = "TextBlock".

Secondly, I thought of inheriting the Polygon class and see if I can do anything there but that class is sealed.

Any ideas on how to achieve this?

like image 511
Frank Q. Avatar asked Mar 13 '12 04:03

Frank Q.


People also ask

How do I add text to XAML?

Here's how to create a TextBox in XAML and in code. TextBox textBox = new TextBox(); textBox. Width = 500; textBox.

How do you add a TextBox in WPF?

Creating a TextBox The Name attribute represents the name of the control, which is a unique identifier of a control. The code snippet in Listing 1 creates a TextBox control and sets the name, height, width, and content of a TextBox control. Text="Hello! I am a TextBox.">


1 Answers

In WPF XAML you could do something simple like this:

<Grid Width="60" Height="100">
    <Ellipse Fill="Yellow"/>
    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="Hello"/>
</Grid>

To get text in the centre of a yellow ellipse.

I'm guessing something that simple will work on WinRT.

like image 58
Phil Avatar answered Dec 17 '22 05:12

Phil