Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 WPF 中:
<Button Width="24" Height="24" > <Image Source="pack://application:,,,/res/x.png" VerticalAlignment="Center"/> </Button>
我如何在 C# 中模仿这个?我在类中找不到任何Button添加孩子的方法。
Button
Button是一个Content控件,所以你只需要使用该Buttons Content属性
Content
Buttons
例子:
Button myButton = new Button { Width = 24, Height = 24, Content = new Image { Source = new BitmapImage(new Uri("image source")), VerticalAlignment = VerticalAlignment.Center } };