XAML 路径 - 添加文本

Edd*_*die 0 xaml

我已经创建了以下 XAML 路径,但想向其中添加文本“返回”。

在此处输入图片说明

这就是我添加它的方式...

   <Path Style="{StaticResource BackButton}">

   </Path>
Run Code Online (Sandbox Code Playgroud)

但是,当我在路径中添加任何内容时,我收到消息

The type 'Path' does not support direct content.
Run Code Online (Sandbox Code Playgroud)

有小费吗?

编辑 - 这是样式

   <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>
Run Code Online (Sandbox Code Playgroud)

Mic*_*elS 6

您可以将形状和 aTextBlock放在 a 内Canvas,并将文本放在形状的顶部。

例如:

<Canvas>
    <Path Style="{StaticResource BackButton}"/>
    <TextBlock Text="Back" Canvas.Top="0" Canvas.Left="25" FontSize="20"/>
 </Canvas>
Run Code Online (Sandbox Code Playgroud)

会给你:

在此处输入图片说明

您也可以仅使用 aGrid作为容器并将TextBlock Panel.ZIndex属性更改为更高的值:

 <Grid>           
        <Path Style="{StaticResource BackButton}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"/>          
        <TextBlock Text="Back" FontSize="20" Panel.ZIndex="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>                    
  </Grid>
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅本教程