以编程方式在Button内添加图像

在WPF中:

 

我怎样才能在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中添加Image并将Source绑定到视图模型中的属性?