How to add text inside a form in XAML

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

At first I thought about defining my own Controltemplate and applying it to a Textblock, but unfortunately it does not understand TargetType = "TextBlock".

Secondly, I was thinking about inheriting the Polygon class and see if I can do anything, but this class is sealed.

Any ideas on how to achieve this?

thanks

+6
source share
2 answers

In WPF Xaml, you can do something simple:

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

Get text in the center of a yellow ellipse.

I guess something that simple will work on WinRT.

+14
source

So late, but you can use something like this with ContentControl or so many other controls:

 <ContentControl Width="200" Height="100" Content="Something"> <ContentControl.Template> <ControlTemplate> <Grid> <Ellipse Fill="Red"/> <TextBlock Text="{Binding Content,RelativeSource={RelativeSource FindAncestor,AncestorType=ContentControl}}" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center"/> </Grid> </ControlTemplate> </ContentControl.Template> </ContentControl> 
0
source

Source: https://habr.com/ru/post/910561/


All Articles