在代码中更改图像源的背后 - WPF [英] Change image source in code behind - Wpf

查看:118
本文介绍了在代码中更改图像源的背后 - WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要动态设置图像源,请注意我的形象在网络上的某个地方,这里是我的代码

I need to set image source dynamically, please note my image is in somewhere on the Network, here is my code

   BitmapImage logo = new BitmapImage();
   logo.BeginInit();
   logo.UriSource = new Uri(@"pack://application:,,,\\myserver\\folder1\\Customer Data\\sample.png");
   logo.EndInit(); // Getting exception here
   ImageViewer1.Source = logo;



例外:的URI前缀无法识别

推荐答案

您只需要一行:

ImageViewer1.Source = new BitmapImage(new Uri(@"\myserver\folder1\Customer Data\sample.png"));

这篇关于在代码中更改图像源的背后 - WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆