Budda
Budda

Reputation: 18343

Silverlight: why png-image is not displaying?

In Silverlight 4 application there are few images, both are displayed correctly in design mode, one is displayed correctly in run-time also:

<Image Height="180" Width="149" Source="../Picts/Field.png" />

Another one is not displayed in run-time:

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5" Visibility="{Binding SquadSavedVisibility, Mode=OneWay}">
    <Image Source="..\Picts\ok.png" Width="16" Height="16" />
    <TextBlock Text=" It is saved" Foreground="Green"/>
</StackPanel>

Why? And how to get it displayed?

Any thoughts are welcome. Thanks.

Upvotes: 0

Views: 3789

Answers (3)

dipak
dipak

Reputation: 2033

I had a similar problem with images showing in design-time, but not at runtime. Mine was using a pack URI so I wanted to post that fix as well:

Does not work at runtime, does work at design-time:

<Image Source="mydllname;component/Images/logo.png" />

Works at both design and runtime:

<Image Source="/mydllName;component/Images/logo.png" />

Note the extra '/' before the Pack URI starts.

Upvotes: 4

Wouter Janssens
Wouter Janssens

Reputation: 1613

You can try to hook into the Image.ImageFailed Event. For examples and more explanation you look into this page:
http://msdn.microsoft.com/en-us/library/system.windows.controls.image.imagefailed%28v=VS.95%29.aspx

Upvotes: 1

Evan Hutnick
Evan Hutnick

Reputation: 534

It's all in your slashes, VS Design time doesn't mind you using "..\Picts\ok.png", but Silverlight runtime wants to see "../Picts/ok.png". In other words, your slashes matter.

Upvotes: 8

Related Questions