Adam Rackis
Adam Rackis

Reputation: 83366

Silverlight - bind to URL

For some reason when I put

"Img/Covers/Medium/106.jpg"

EDIT:

<Image Grid.Column="0" Stretch="None" HorizontalAlignment="Left" Source="Img/Covers/Medium/106.jpg" Margin="7,0,0,0"></Image>

As the Source for an Image, it works perfectly. But when I try to bind the Source to a property defined as such, it doesn't find it.

public virtual Uri MediumImgURI {
    get { return new Uri("Img/Covers/Medium/106.jpg"); }
}

EDIT:

<Image Grid.Column="0" Stretch="None" HorizontalAlignment="Left" Source="{Binding Path=MediumImgURI}" Margin="7,0,0,0"></Image>

Is there something special I have to do to get the latter case to work?

EDIT: Also, making that property a string, instead of Uri causes it to work, but this is an over-simplification - I really need to get it to work with the property as Uri.

EDIT:

When I was linking to images that were in my website, and not my SL app, I had this code (which worked)

public virtual string MediumImgURI {
    get { return new Uri(App.Current.Host.Source, String.Format("../Img/Medium/{0}.jpg", CurrentBook.smallID)); }
}

When linking instead to an image in my SL app I thought I could just leave off the first parameter, but it appears not.

Upvotes: 0

Views: 680

Answers (2)

Adam Rackis
Adam Rackis

Reputation: 83366

Sorry everyone - I did a poor job of researching this myself before asking. As noted here,

https://stackoverflow.com/questions/20586/wpf-image-urisource-and-data-binding

it needs to be a Uri relative to the xap file, so I need a ../ in front of my address.

Thanks for answering.

Upvotes: 0

Todd Davis
Todd Davis

Reputation: 6035

Yes, hard to tell from what you have posted. It may be that your binding is failing. Try pulling it up in SilverlightSpy3 and see what the Source is for that image.

Upvotes: 2

Related Questions