【问题标题】:How do I place a text over a image in a button in WinRT如何在 WinRT 中的按钮中的图像上放置文本
【发布时间】:2023-03-15 17:34:01
【问题描述】:

我想创建一个使用图像作为背景的按钮,我想在背景上放置我的文本。

我尝试过这样的事情:

<Button Style="{StaticResource ImageButtonStyle}">
    <StackPanel>
        <TextBlock Text="test"></TextBlock>
        <Image Source="ms-appx:///Skins/Images/buton.png" Stretch="None" />
    </StackPanel>
</Button>

文本不会正确居中。

<Button Style="{StaticResource ImageButtonStyle}">
    <StackPanel>
        <TextBlock Text="test"></TextBlock>
        <Label Padding="0">My Button Text</Label>
    </StackPanel>
</Button>

控件Label 不存在。

如何在第一次尝试时将我的文本正确地居中放置在图像上? 你知道更好的方法吗?

【问题讨论】:

    标签: c# .net xaml windows-runtime


    【解决方案1】:

    您应该在堆栈面板中使用网格。试试这样的:

     <Button >
            <Grid>
                <Image Source="..." Stretch="None" />
                <TextBlock Text="test" VerticalAlignment="Center" HorizontalAlignment="Center"/>
            </Grid>
      </Button>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-23
      • 2012-02-25
      • 2013-11-28
      • 2011-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多