如何将网格的背景更改为 WP7 silverlight 中的图像? [英] How to change the background of a grid to an image in WP7 silverlight?

查看:24
本文介绍了如何将网格的背景更改为 WP7 silverlight 中的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 WP7 silverlight 中的网格控件设置背景,我需要以编程方式进行,而不是在设计中.

I'm trying to set a background for a grid control in WP7 silverlight, I need to do that programatically, not in the desighn.

我尝试了类似的方法:

ContentPanel.Background = new BitmapImage(new Uri("ImagesBackgroundswith box13.jpg", UriKind.Relative));

当然,我得到了一个错误,因为在右边我们应该有类型 SolidColorBrush.

But of course, I got an error, because on the right hand we should have the type SolidColorBrush.

有没有办法做到这一点?

is there a way to do that?

谢谢..

推荐答案

我首先建议您使用 Canvas 而不是 Grid.您可以通过删除 Grid 并通过 Toolbox -> Drag and Drop 插入 Canvas 来做到这一点.

I would firstly recommend that you use a Canvas instead of a Grid. You can do this by deleting the Grid and inserting a Canvas through the Toolbox -> Drag and Drop.

然后,您可以使用如下简单的代码:

Then, you can use the code as simple as:

ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = new BitmapImage(new Uri("url", UriKind.Relative));
CanvasName.Background = imageBrush;

这会将背景更改为您想要的任何内容.

That will change the background to whatever you want.

希望对您有所帮助.

这篇关于如何将网格的背景更改为 WP7 silverlight 中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆