如何在wpf中设置Image.Source运行时. [英] How To Set Image.Source runtime in wpf.
本文介绍了如何在wpf中设置Image.Source运行时.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的xaml页面页面中添加了一个图像控件,如下所示:
Hi ,
I have added one image control in my xaml page page as
<Image x:Name="imgQRCode" Grid.Column="0" HorizontalAlignment="Left" Height="439" Margin="10,51,0,0" VerticalAlignment="Top" Width="418" />
我想在运行时设置其图像路径.
为此,我正在尝试这种方式
and I want to set its image path at runtime.
For this I am trying this way
imgQRCode.Source = new BitmapImage(new Uri("D:\\sample.bmp"));
它没有给出任何错误;但是此示例图像也不会在运行时显示.
请提出我错了的地方或进一步指导.
预先感谢.
Its not giving any error;but This sample image also not displayed at runtime.
Please suggest where I am wrong or guide further.
Thanks in advance.
推荐答案
您的代码似乎还可以,尽管使用WPF,绑定仍可以正常使用.
那行代码根本没有被调用吗?
是在其他线程中调用的吗?在这种情况下,应使用类型为BitmapImage
的局部变量,加载位图并Freeze()
,然后设置属性.
Your code seems ok, though with WPF, binding is used normally.
Is that line of code called at all?
Is it called in a different thread? In that case, you should use a local variable of typeBitmapImage
, load the bitmap andFreeze()
it, then set the property.
我认为这将是
i think this will be
imgQRCode.Source = new BitmapImage(new Uri("D://sample.bmp"));
这篇关于如何在wpf中设置Image.Source运行时.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文