How to display an image brush in the background of a border

802 Views Asked by At

i'm trying to display an image as the background of a border element

<Border>                
     <Border.Background>
        <ImageBrush Stretch="Fill">
            <ImageBrush.ImageSource>
                <BitmapImage UriSource="http://10.218.23.10/myPic.jpg" />
            </ImageBrush.ImageSource>
        </ImageBrush>
     </Border.Background>
</Border>

i was told should use an ImageBrush instaed of an Image

(1) what benefits does using an ImageBrush Have over an Image ?

(2) if i display my picture using an Image , it does in fact show the image

      <Border>
           <Image Source="http://10.218.23.10/myPic.jpg"/>
      </Border>

can this kind of scenario only be done with an image ?

1

There are 1 best solutions below

0
On

Your first code may not display anything because the Border does not take any space or because the content is obstructing the background, which is the image.

Whether you use an Image or an ImageBrush depends on how you want it to behave, an Image is a control that partakes in the layout while a brush just paints something with an image. I for one pretty much never use the brush because my images or often icons or something prominently displayed, if you however have some background that should have some design or pattern as a background then the bursh might be a good choice.