C# 如何在WinRT中的按钮中将文本放置在图像上
我想创建一个按钮,使用图像作为背景,并在背景的顶部放置文本 我试过这样的方法:C# 如何在WinRT中的按钮中将文本放置在图像上,c#,.net,xaml,windows-runtime,C#,.net,Xaml,Windows Runtime,我想创建一个按钮,使用图像作为背景,并在背景的顶部放置文本 我试过这样的方法: <Button Style="{StaticResource ImageButtonStyle}"> <StackPanel> <TextBlock Text="test"></TextBlock> <Image Source="ms-appx:///Skins/Images/buton.png" Stretch="None
<Button Style="{StaticResource ImageButtonStyle}">
<StackPanel>
<TextBlock Text="test"></TextBlock>
<Image Source="ms-appx:///Skins/Images/buton.png" Stretch="None" />
</StackPanel>
</Button>
<Button >
<Grid>
<Image Source="..." Stretch="None" />
<TextBlock Text="test" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Button>
文本将无法正确居中
<Button Style="{StaticResource ImageButtonStyle}">
<StackPanel>
<TextBlock Text="test"></TextBlock>
<Label Padding="0">My Button Text</Label>
</StackPanel>
</Button>
我的按钮文本
控件标签
不存在
如何在第一次尝试时将文本正确居中放置在图像上?
您知道更好的方法吗?您应该使用网格安装stackpanel。试着这样做:
<Button Style="{StaticResource ImageButtonStyle}">
<StackPanel>
<TextBlock Text="test"></TextBlock>
<Image Source="ms-appx:///Skins/Images/buton.png" Stretch="None" />
</StackPanel>
</Button>
<Button >
<Grid>
<Image Source="..." Stretch="None" />
<TextBlock Text="test" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Button>
您应该使用网格安装stackpanel。试着这样做:
<Button Style="{StaticResource ImageButtonStyle}">
<StackPanel>
<TextBlock Text="test"></TextBlock>
<Image Source="ms-appx:///Skins/Images/buton.png" Stretch="None" />
</StackPanel>
</Button>
<Button >
<Grid>
<Image Source="..." Stretch="None" />
<TextBlock Text="test" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Button>