添加图片我试过这个解决方案:在WPF按钮
<Button>
<StackPanel>
<Image Source="Pictures/img.jpg" />
<TextBlock>Blablabla</TextBlock>
</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;
我得到异常的 “在PresentationFramework.dll 'System.Windows.Markup.XamlParseException'”。
你能帮我找到解决办法吗? 谢谢。
您的图像在其属性中是否定义为“资源”? (右键单击它 - >属性 - >生成操作='资源') –
谢谢!你把我放在正确的方向:我拖放图像到解决方案资源管理器,现在我可以看到它:) – Marco