控件模板中从web加载图像的问题
我尝试从数据库中读取html内容并将其显示在页面中:
我为该控件设计了一个控件模板,generic.xaml喜欢以下内容:
我从html内容中获取这些图片并将其添加到QuestionTitleParagraph中,因此我编写了以下代码以在OnApplyTemplate中显示图像:
公共覆盖OnApplyTemplate() { base.OnApplyTemplate();//从数据库获取图像url,下面的映像仅供测试ImageSource imageSource =新BitmapImage(“http://localhost:8081/uploadfile/2012/07/19/temp1.png", (UriKind.Absolute);图像img =新图像();img.Source = imageSource;img.Width = 100;img.Height = 100; //将图像添加到(Paragraph)base.GetTemplateChild("QuestionTitleParagraph");QuestionTitleParagraph = QuestionTitleParagraph InlineUIContainer容器=新的InlineUIContainer();container.Child = img;QuestionTitleParagraph.Inlines.Add(container);}
我的问题是,它只是在我的页面中显示一个空白的图像,大小与我所期望的(100*100)相同。如何在控制模板中动态显示图像?我确信图像url是有效的,我可以在richtextblock中显示它,而不是在控制模板中。我发现,如果不设置图像的宽度和高度,它也不能在richtextblock中显示。
发布于 2013-01-03 15:43:37
你试过改变图片格式吗?
https://stackoverflow.com/questions/14142108
复制相似问题