如何设置框架的背景图像?

Edw*_*ard 3 c# windows-phone-7

我知道在这篇文章中他们使用所遵循的步骤设置背景颜色.我想知道是否有使用图像而不是颜色的方法.我尝试了以下但它不起作用:

ImageBrush brush = new ImageBrush();
brush.ImageSource = 
new BitmapImage(new Uri("/MyApp;component/Images/Backgrounds/myimage.jpg"));
Rootframe.Background = brush;
Run Code Online (Sandbox Code Playgroud)

有没有人看过这是否可能?还是仅限于颜色?

key*_*rdP 5

我决定去吧,让它运转起来.唯一的问题是,这是一个解决方法,因为ImageOpened事件似乎有一些奇怪的行为.基本上,当您将背景分配给帧时,不会调用ImageOpened事件Brush.奇怪的是,当你将它分配给一个元素时,它会被调用.所以我只是创建了一个隐藏按钮并将画笔指定给它(以强制ImageOpened事件触发).然后我将它分配到框架,它适用于我.看起来像一个错误,但下面的解决方法适合我.

ImageBrush brush = new ImageBrush();

brush.ImageSource = new BitmapImage(new Uri("/myImage.jpg", UriKind.Relative));
//hide the fake button and set the brush to be its background
button1.Visibility = System.Windows.Visibility.Collapsed;
button1.Background = brush;

//assign it to the frame (or using RootFrame in your case)
var frame = App.Current.RootVisual as PhoneApplicationFrame;
frame.Background = brush;
Run Code Online (Sandbox Code Playgroud)