XAML 路径 - 添加文本 [英] XAML Path - Add Text

查看:19
本文介绍了XAML 路径 - 添加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have made the following XAML path but would like to add the text 'Back' to it.

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

This is how I am adding it in...

   <Path Style="{StaticResource BackButton}">

   </Path>

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

However when I add any content inside the path I get the message

The type 'Path' does not support direct content.

有什么建议吗?

编辑 - 这是样式

   <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>

推荐答案

您可以将形状和 TextBlock 放在 Canvas 中,并将文本放在顶部形状.

You can place both the shape and a TextBlock inside a Canvas, and place the text on top of the shape.

例如:

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

会给你:

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

You can also just use a 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>

参见 本教程了解更多详情.

这篇关于XAML 路径 - 添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆