在 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# - 以编程方式在按钮内添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15627123/