如何在代码隐藏中使用BitmapImage设置ImageSource路径
我正在尝试使用 VS2010 项目的 Images 文件夹中的背景图像。我已阅读文档,并尝试了多种方法,包括以下方法,但无法使其工作:
ImageBrush bg2 = new ImageBrush();
bg2.ImageSource = new BitmapImage(new Uri(@"/FooApplication1;component/Images/bg1.png"));
ImageBrush bg1 = new ImageBrush();
bg1.ImageSource = new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "/FooApplication;component/Images/bg1.png"));
有人知道出了什么问题吗?
I'm trying to a Background image which is in my VS2010 project's Images folder. I have read the documentation and I tried several ways including following but can't get it to work:
ImageBrush bg2 = new ImageBrush();
bg2.ImageSource = new BitmapImage(new Uri(@"/FooApplication1;component/Images/bg1.png"));
ImageBrush bg1 = new ImageBrush();
bg1.ImageSource = new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), "/FooApplication;component/Images/bg1.png"));
Anyone knows what's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 URI 应该如下所示:
您阅读过 这篇关于 URI 的文章?
I think the URI should look something like this:
Did you read this article on URIs?