以编程方式在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
绑定到视图模型中的属性?