在WPF中将图像设置为网格 [英] set image to grid in WPF
本文介绍了在WPF中将图像设置为网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好专家,
我想将图像设置为网格.我正在使用C#n WPF.
我正在使用以下代码,但无法正常工作.
Hello Experts,
I want to set image to grid.I am working with C# n WPF.
I am using following code but not working.
ImageBrush myBrush = new ImageBrush();
Image image = new Image();
image.Source = new BitmapImage(new Uri("pack://application:,,,MyClassLibrary;component/Images/myImage.jpg"));
myBrush.ImageSource = image.Source;
Grid grid = new Grid();
grid.Background = myBrush;
谢谢
Thanks
推荐答案
ImageBrush myBrush = new ImageBrush();
myBrush.ImageSource = new BitmapImage
(new Uri(@"pack://application:,,,/Resources;component/Images/x.jpg"));
grid.Background = myBrush;
您创建了一个新网格并将其放在图像上,但是您看不到网格提示他不是UI对象的一部分
you create a new grid and put the image on it, But you cannot see that grid cuz he is noot a part of the UI objects
它起作用了.
谢谢Mohamed_Ahmed
It works.
Thanks Mohamed_Ahmed
这篇关于在WPF中将图像设置为网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文