【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属性,那是因为图片路径填写错了!


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM