本文介绍了如何在WinRT中的按钮上的图像上放置文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用图像作为背景创建一个按钮,并在背景上方放置文本.
I want to create a button using a image as background and on top of the background I want to place my text.
我尝试过这样的事情:
<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>
控件标签
不存在.
如何在第一次尝试中将文本正确居中?你知道更好的方法吗?
How do I center correctly my text on the image in my first attempt?Do you know a better way?
推荐答案
您应该使用网格代替堆栈面板.尝试这样的事情:
You should use a grid instade the stackpanel. Try something like this:
<Button >
<Grid>
<Image Source="..." Stretch="None" />
<TextBlock Text="test" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Button>
这篇关于如何在WinRT中的按钮上的图像上放置文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!