【问题标题】:Adding an Image inside a Button programmatically以编程方式在按钮内添加图像
【发布时间】:2013-03-26 00:10:29
【问题描述】:

在 WPF 中:

<Button Width="24" Height="24" >
    <Image Source="pack://application:,,,/res/x.png" VerticalAlignment="Center"/>
</Button>

如何在 C# 中模仿这一点?我在Button 类中找不到任何添加子项的方法。

【问题讨论】:

标签: c# wpf button children


【解决方案1】:

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
    }
};

【讨论】:

  • 如果我想将图片添加到带有文本内容的按钮上怎么办?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
  • 1970-01-01
  • 1970-01-01
  • 2019-06-25
  • 2020-09-23
相关资源
最近更新 更多