Image source with custom Http Headers RRS feed

  • Question

  • I'm currently binding my Image Source in XAML to a full URL path. Works like a charm...

    But the web service has changed and now I've to add custom http headers with an applicationKey to access image resources from web. I could also add the http headers as url params.

    Now my 2 problems:
    I've found no way to add additional http headers when binding the image source to an url. Is there any way to do so? I would strongly prefer a way where I can use bindings and avoid code behind.

    If there is no way to add http headers I've to add the applicationKey as url parameter. But the appKey includes a timestamp whereby the url for a specific image is going to change all the time. I guess the default caching won't work since it caches based on the url. I would like to avoid building my own caching algorithm to change this behavior.

    If there is no easy way I would also consider to use 3rd party libaries to get this done if somebody knows of any. 

    Thanks for your help guys!



    Tuesday, May 6, 2014 6:52 AM


  • no this cant be done out of the box. two approach you can do:

    - in your viewmodel download the image with the HttpClient. you can custime the http request to anything you like. Then make a property of BitmapImage. Create new instance of a BitmapImage and load it with the stream you got from the httpclient. Databind against the BitmapImage.

    - second approach; create a AttachedProperty, let that download the image then assign the source of an image element.

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Tuesday, May 6, 2014 9:18 AM