Image.Source using proxy
Question
On my WPF page I have, for example, an image (one or more) like this:
<Image Source="{Binding Path=PicURL}"/>
Also, I have a Settings page with an option to switch ON/OFF the usage of Internet Proxy Settings globally inside my entire Application. If to speak about manual web requests, I can solve it, for example, like this:
HttpWebRequest request = ( HttpWebRequest )WebRequest.Create( ... );
if( UseProxy ) request.Proxy.Credentials = CredentialCache.DefaultCredentials;
else req.Proxy = null;
But it doesn`t work on WPF controls like Image where content is based on URLs and Internet Proxy Settings are used.
Is there a way to switch proxy globally inside entire app at run-time?
La solution
You might be able to modify WebRequest.DefaultWebProxy
If those dont work in your situation then a workaround is you can download the "resource" from the Web yourself using WebRequest with/or without the Proxy settings.
You can use that data returned by the web request as a stream to initialise a BitmapImage which you can then set into the Source, or you could save to a temporary file and make the Source point to that local file.
You would write and use a "Converter" on your Binding which does the downloading/conversion from image Url to BitmapImage, or maybe a MarkupExtension might be possible depending on your situation.
You'd probably want to use Aynchronous bindings, because the download of the image resource might take a while, and you don't want that to block your main UI thread.
Autres conseils
Try this one if you want the proxy settings to be config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy proxyaddress="http://proxyaddress:port"
usesystemdefault="False"
bypassonlocal="True"
autoDetect="False" />
</defaultProxy>
</system.net>
</configuration>
Cheers