Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WinRT中的按钮中将文本放置在图像上_C#_.net_Xaml_Windows Runtime - Fatal编程技术网

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>