WPF - 带有文本和图像的按钮

时间:2016-05-08 17:33:06

标签: wpf button

无法在WPF应用中制作带有图像和文字的按钮。我的代码是这样的:

<Window x:Class="WindowR.One"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WindowR"
        mc:Ignorable="d"
        Title="One" Height="300" Width="300">

    <Grid>
        <StackPanel Orientation="Vertical">
            <TextBlock Text="Click Here" />
            <Image Source="D:\Skola\4. semester\TP\GIT folder\Visualko\Core\WindowR\Pictures\0.png" />
        </StackPanel>
    </Grid>

</Window>

但是文字不在图片之上..从这里开始学习很多教程..但是没有一个能正常工作

1 个答案:

答案 0 :(得分:0)

StackPanel在Image旁边排列TextBlock。尝试使用Grid

<Button Width="120" Height="50" >
    <Grid>
        <Image Source="D:\Skola\4. semester\TP\GIT folder\Visualko\Core\WindowR\Pictures\0.png" />
        <TextBlock Text="Click Here" 
                   VerticalAlignment="Center" 
                   HorizontalAlignment="Center" />
    </Grid>
</Button>