在我的 Windows Phone 7 应用程序中使用动态磁贴,它工作得很好。
我现在正在尝试创建动态动态磁贴,但无法显示背景图像。使用下面的代码时,我只得到一个黑色瓷砖。显示我添加的文本,但不显示背景图像。图像“构建操作”设置为“内容”。
有任何想法吗?
StackPanel sp = new StackPanel();
sp.Height = 173;
sp.Width = 173;
string fileName = "tile.jpg";
BitmapImage image = new BitmapImage(new Uri(fileName, UriKind.Relative));
ImageBrush brush = new ImageBrush();
brush.ImageSource = image;
sp.Background = brush;
sp.Measure(new Size(173, 173));
sp.Arrange(new Rect(0, 0, 173, 173));
sp.UpdateLayout();
WriteableBitmap wbm = new WriteableBitmap(173, 173);
wbm.Render(sp, null);
wbm.Invalidate();