如何将网格的背景更改为WP7 Silverlight中的图像? [英] How to change the background of a grid to an image in WP7 silverlight?
问题描述
我想设置背景为WP7的Silverlight网格控制,我需要做的编程,而不是在desighn。
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("Images\Backgrounds\with box\13.jpg", UriKind.Relative));
但当然,我得到一个错误,因为在右边我们应该有的SolidColorBrush
But of course, I got an error, because on the right hand we should have the type SolidColorBrush
.
是有办法做到这一点?
Thanks ..
Thanks..
推荐答案
我首先建议您使用Canvas而不是Grid。您可以通过删除电网和从工具箱中插入一个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屋!