Windows Phone 7.1 - How to change background image on button press?
How do I change the background image of some canvas from withing the c# code on button press? I know how to change the background color:
Canvas1.Background = new SolidColorBrush(Colors.Red);
I found a tutorial online , but VS says that "The type or namespace name 'BitmapImage' could not be found (are you missing a using directive or an assembly reference?)"
var brush = new ImageBrush();
brush.ImageSource开发者_开发百科 = new BitmapImage(new Uri(@"Images/myImage.png", UriKind.Relative));
Canvas1.Background = brush;
What am I missing?
TIA!
You need to add a reference to the System.Windows.Media.Imaging
namespace. Add this to the top of your class, where the other using directives
are.
using System.Windows.Media.Imaging;
精彩评论