c# – 以编程方式在Button中添加图像

c# – 以编程方式在Button中添加图像,第1张

概述在 WPF中: <Button Width="24" Height="24" > <Image Source="pack://application:,,,/res/x.png" VerticalAlignment="Center"/></Button> 我怎样才能在C#中模仿这个?我在Button类中找不到添加子项的任何方法. Button是一个Content控件,因此您只需使用But 在 WPF中:
<button WIDth="24" Height="24" >    <Image Source="pack://application:,/res/x.png" VerticalAlignment="Center"/></button>

我怎样才能在C#中模仿这个?我在button类中找不到添加子项的任何方法.

解决方法 button是一个Content控件,因此您只需使用buttons Content属性

例:

button mybutton = new button{    WIDth = 24,Height = 24,Content = new Image    {        Source = new BitmAPImage(new Uri("image source")),VerticalAlignment = VerticalAlignment.Center    }};
总结

以上是内存溢出为你收集整理的c# – 以编程方式在Button中添加图像全部内容,希望文章能够帮你解决c# – 以编程方式在Button中添加图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1240968.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存