tags:

views:

18

answers:

1

I have a StackPanel containing five images and I want to put a black border around each image.

The XAML I have at the moment is:

<Image Name="imgPic1"
       Width="100"
       Height="75"
       Stretch="Fill"
       VerticalAlignment="Top" />

I thought I would be just able to put a one-unit margin or padding on the image and set a background color to 000000 but Padding and Background are both invalid for images.

What is an easy way to do this in XAML? Do I really have to put each image inside another control to get a border around it or is there some other trickery I can use?

+2  A: 

Simply wrap the Image in a Border control

<Border BorderThickness="1">
    <Image Name="imgPic1"
           Width="100"
           Height="75"
           Stretch="Fill"
           VerticalAlignment="Top" />
</Border>

You could also provide a style you apply to images that does this if you don't want to do it around every image


Final solution from answer and comments added by Pax:

<Border BorderThickness="1"
        BorderBrush="#FF000000"
        VerticalAlignment="Top">
    <Image Name="imgPic1"
           Width="100"
           Height="75"
           Stretch="Fill"
           VerticalAlignment="Top"/>
</Border>
Craig Suchanec
That looks good but how do I make it black? Setting Background affects the space around the border, not the border itself, and there's no Color or Foreground property.
paxdiablo
You have to use the BorderBrush property. You can specify a hex color there or you can specify a more complex brush. If you want it to be black it'd be BorderBrush="#FF000000"
Craig Suchanec
Thanks for that, Craig. It works fine now.
paxdiablo