在按钮+;WPF

在按钮+;WPF,wpf,xaml,Wpf,Xaml,各位,我想创建作为附加图像的按钮。我想把文字放在图像上。有人遇到过这种情况吗?请帮我解决这个问题。您可以通过将文本块添加到与图像相同的网格,将文本置于图像顶部,例如: <Button> <Button.Template> <ControlTemplate TargetType="Button"> <Grid> <Image Source="pic.png" Str

各位,我想创建作为附加图像的按钮。我想把文字放在图像上。有人遇到过这种情况吗?请帮我解决这个问题。

您可以通过将文本块添加到与图像相同的网格,将文本置于图像顶部,例如:

<Button>
    <Button.Template>
        <ControlTemplate TargetType="Button">
            <Grid>
                <Image Source="pic.png" Stretch="None" />
                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">Operation</TextBlock>
            </Grid>
        </ControlTemplate>
    </Button.Template>
</Button>

活动
如果要旋转文本,可以对其应用旋转变换:

<Button>
    <Button.Template>
        <ControlTemplate TargetType="Button">
            <Grid>
                <Image Source="pic.png" Stretch="None" />
                <TextBlock Text="Operation" VerticalAlignment="Center" HorizontalAlignment="Center">
                    <TextBlock.LayoutTransform>
                        <RotateTransform Angle="-90" />
                    </TextBlock.LayoutTransform>
                </TextBlock>
            </Grid>
        </ControlTemplate>
    </Button.Template>
</Button>

您可以通过将文本块添加到与图像相同的网格,将文本置于图像顶部,例如:

<Button>
    <Button.Template>
        <ControlTemplate TargetType="Button">
            <Grid>
                <Image Source="pic.png" Stretch="None" />
                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">Operation</TextBlock>
            </Grid>
        </ControlTemplate>
    </Button.Template>
</Button>

活动
如果要旋转文本,可以对其应用旋转变换:

<Button>
    <Button.Template>
        <ControlTemplate TargetType="Button">
            <Grid>
                <Image Source="pic.png" Stretch="None" />
                <TextBlock Text="Operation" VerticalAlignment="Center" HorizontalAlignment="Center">
                    <TextBlock.LayoutTransform>
                        <RotateTransform Angle="-90" />
                    </TextBlock.LayoutTransform>
                </TextBlock>
            </Grid>
        </ControlTemplate>
    </Button.Template>
</Button>