我不能用图像填充矩形对象。
ImageBrush ib = new ImageBrush();
BitmapImage bmi = new BitmapImage(new Uri(@"/WpfImageApp;component/Images/Penguins.jpg", UriKind.Relative));
ib.ImageSource = bmi;
body.Fill = ib;主体是矩形对象,当我运行这段代码时,窗口上只有黑屏。我也看不到我的其他控制器(如按钮)。有什么解决方案吗?
发布于 2012-06-14 16:27:44
在复制完您所做的工作之后,我可以确认,如果BitmapImage无法加载到构造函数中,您将看到一个黑色窗口,其中没有任何控件。
将您的代码移动到一个在窗口加载后可以单击的按钮,您将看到正确的错误消息。
Could not find a part of the path 'C:\WpfImageApp;component\Images\Penguins.jpg'.将URI更改为pack://application:,,,/Images/Penguins.jpg后,图像将正确加载
https://stackoverflow.com/questions/11029158
复制相似问题