【发布时间】:2013-03-26 00:10:29
【问题描述】:
在 WPF 中:
<Button Width="24" Height="24" >
<Image Source="pack://application:,,,/res/x.png" VerticalAlignment="Center"/>
</Button>
如何在 C# 中模仿这一点?我在Button 类中找不到任何添加子项的方法。
【问题讨论】:
在 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
}
};
【讨论】: