新手问一个动态生成的Button的背景图片有关问题


新手问一个动态生成的Button的背景图片问题
我在WPF的后台代码中生成了许多个按钮,本来我是用

  ImageBrush im = new ImageBrush();
im.ImageSource = new BitmapImage(new Uri(@"../../Image/1.bmp", UriKind.RelativeOrAbsolute));
a.Background = im;

这样的代码来设置背景图片的,但是后来发现,这样的话,生成的exe文件被移出去以后就找不到原来的图片了。所以现在想用Properties.Resources里面的资源图片,但是不知道如何在代码里设置,求各位大神指教!


SilverLight .net 程序开发

淡定的忧郁 11 years, 6 months ago



  ImageBrush im = new ImageBrush();
im.ImageSource = new BitmapImage(new Uri(@"pack://application:,,,/Images/Tulips.jpg", UriKind.RelativeOrAbsolute));
a.Background = im;

一顾倾人城 answered 11 years, 6 months ago

Your Answer