【WPF】Button按钮添加背景图片

只是想做一个很简单的图片按钮而已,不需要那么复杂。

<Button x:Name="btn" Width="145" Height="30" HorizontalAlignment="Center" Margin="5"  VerticalAlignment="Top" Command="{Binding BtnCommand}"> 
    <Button.Background>
        <ImageBrush ImageSource="图片路径" Stretch="Fill"/> <!--如"/项目名;component/Presentation/Resources/Images/1.png"-->
    </Button.Background>
</Button>

坑点:

  • 如果Visual Studio报错说在Button下找不到Background属性,那是因为图片路径填写错了!
原文地址:https://www.cnblogs.com/guxin/p/wpf-set-button-background-image.html