【问题标题】:How to change the background of a grid to an image in WP7 silverlight?如何将网格的背景更改为 WP7 silverlight 中的图像?
【发布时间】:2012-06-08 13:14:11
【问题描述】:

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

我尝试了类似的方法:

ContentPanel.Background = new BitmapImage(new Uri("Images\Backgrounds\with box\13.jpg", UriKind.Relative));

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

有没有办法做到这一点?

谢谢..

【问题讨论】:

    标签: silverlight windows-phone-7 grid


    【解决方案1】:

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

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

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

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

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 2013-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多