Results 1 to 5 of 5

Thread: [RESOLVED] Silverlight Image

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    21

    Resolved [RESOLVED] Silverlight Image

    I have an image in a silverlight project. When I click a button I want the image to change to another image.

    I saw that there is an imagesource property but I cannot simply put the Url of the new image in there.

    Can someone help

    Thanks
    Pete

  2. #2
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Silverlight Image

    Typed this straight in so apologies in advance for syntax errors.

    Make sure you've imported System.Windows.Resources and System.Windows.Media.Imaging

    If TheImage.png is located in Images folder and build action is set to Resource:

    Code:
    Dim sri As StreamResourceInfo = Application.GetResourceStream(New Uri("SilverlightApplication1;component/Images/TheImage.png", UriKind.Relative))
    Dim bmp As New BitmapImage
    bmp.SetSource(sri.Stream)
    
    image1.Source = bmp
    If TheImage.png is located in Images folder and build action is set to Content:

    Code:
    Dim sri As StreamResourceInfo = Application.GetResourceStream(New Uri("Images/TheImage.png", UriKind.Relative))
    Dim bmp As New BitmapImage
    bmp.SetSource(sri.Stream)
    
    image1.Source = bmp
    If TheImage.png is somewhere out on the web:

    Code:
    image1.Source = New BitmapImage(New Uri("http://domain.com/TheImage.png", UriKind.Absolute))

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    21

    Re: Silverlight Image

    Thanks. But I am having trouble with bmp.sersource.

    BMP does not seem to have that method.

  4. #4
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Silverlight Image

    It's definitely available in Silverlight 3 when I try it. BitmapImage should be in System.Windows.Media.Imaging.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    21

    Re: Silverlight Image

    This is how I got it to work.

    Image1.Source = New BitmapImage(New Uri("Photos/BrownBush.jpg", UriKind.RelativeOrAbsolute))

    I had trouble with the code you sent Matt. I really don't know why. But this seemed to do the trick. Thanks for you help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width