Design time and image path relative. VERY ANOYING... RRS feed

  • Question

  • Hi,

    There's something very anoying to me which is when I do add an image at design time that Expression Blend get a copy and place the image in the Silverlight application directory.  So Very often, I do add static images at design time and doing so I have tons of images in this directory in my Solution Explorer and this is awful.

    Is there any way to add an image from ClientBin\Images\WHERE_ALL_MY_IMAGES_ARE and make sure Expression Blend will let the image there.  Don't bring it in the silverlight directory.  That way I will always keep my silverlight directory clean and the images are there because my application at runtime go get all the images there.

    Tuesday, July 14, 2009 10:20 AM

All replies

  • It sounds like you're hard-coding images on the page. A better way to handle them is to create a ResourceDictionary (I creatively call mine Images.xaml) and set your images as resources. The code looks like this:

    <BitmapImage x:Key="HomeButton" UriSource="Images\HomeButton.png" />

    Now you can call HomeButton as a resource wherever you need it. This also has the added benefit of letting you swap out the image file across the app when you decide your HomeButton should be blue instead of green.

    e: I forgot to mention, for this to work correctly you'll need to Include HomeButton.png in your project, otherwise you'll see the graphic in Blend but not at runtime.

    • Proposed as answer by VLTII Tuesday, July 14, 2009 6:26 PM
    Tuesday, July 14, 2009 6:25 PM