XAML Path - Add Text

I made the following XAML path, but would like to add the text “Back” to it.

enter image description here

This is how I add it to ...

<Path Style="{StaticResource BackButton}"> </Path> 

However, when I add content inside the path, I get a message

 The type 'Path' does not support direct content. 

Any tips?

Change is a style

  <Style x:Key="BackButton" TargetType="{x:Type Path}"> <Setter Property="Data" Value="F1 M 639.667,236.467L 645.092,236.467L 725.566,236.467L 725.566,253.513L 645.092,253.513L 639.673,253.513L 619.787,244.99L 639.667,236.467 Z " /> <Setter Property="Height" Value="30" /> <Setter Property="MinWidth" Value="100" /> <Setter Property="Fill" Value="#FFFFFFFF" /> <Setter Property="StrokeThickness" Value="1" /> <Setter Property="Stroke" Value="#FF999B9C" /> <Setter Property="Stretch" Value="Fill" /> <Setter Property="Cursor" Value="Hand" /> <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Fill" Value="#FFEEEEEE" /> </Trigger> </Style.Triggers> </Style> 
0
source share
1 answer

You can put both form and TextBlock inside the Canvas , and place the text on top of the form.

For instance:

 <Canvas> <Path Style="{StaticResource BackButton}"/> <TextBlock Text="Back" Canvas.Top="0" Canvas.Left="25" FontSize="20"/> </Canvas> 

You'll get:

enter image description here

You can also just use the Grid as a container and change the TextBlock Panel.ZIndex property to a higher value:

  <Grid> <Path Style="{StaticResource BackButton}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"/> <TextBlock Text="Back" FontSize="20" Panel.ZIndex="1" HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid> 

See this tutorial for more details.

+3
source

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


All Articles