如何在 WinRT 中的按钮中将文本放置在图像上
How do I place a text over a image in a button in WinRT
我想创建一个使用图像作为背景的按钮,我想在背景之上放置我的文字。
我试过这样的事情:
<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
不存在。
如何在第一次尝试时将文本正确地居中放置在图像上?
你知道更好的方法吗?
您应该使用网格代替堆栈面板。尝试这样的事情:
<Button >
<Grid>
<Image Source="..." Stretch="None" />
<TextBlock Text="test" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Button>
我想创建一个使用图像作为背景的按钮,我想在背景之上放置我的文字。
我试过这样的事情:
<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
不存在。
如何在第一次尝试时将文本正确地居中放置在图像上? 你知道更好的方法吗?
您应该使用网格代替堆栈面板。尝试这样的事情:
<Button >
<Grid>
<Image Source="..." Stretch="None" />
<TextBlock Text="test" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Button>