5
在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
}
};
为什么不在XAML中添加图像并将Source
绑定到视图模型中的属性?
http://stackoverflow.com/questions/4271277/programmatically-creating-image-button -in-WPF – 2013-03-26 00:20:36