【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-2026 CODEPRJ.COM