如何使用后面的 C# 代码在 Button 中添加 StackPanel(即将以下 XAML 转换为 C#)?没有 Button.Children.Add
...
<Button>
<StackPanel Orientation="Horizontal" Margin="10">
<Image Source="foo.png"/>
</StackPanel>
</Button>
最佳答案
Image img = new Image();
img.Source = new BitmapImage(new Uri("foo.png"));
StackPanel stackPnl = new StackPanel();
stackPnl.Orientation = Orientation.Horizontal;
stackPnl.Margin = new Thickness(10);
stackPnl.Children.Add(img);
Button btn = new Button();
btn.Content = stackPnl;
关于c# - 如何在 C# 代码后面的按钮中添加 StackPanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5390270/