views:

287

answers:

2
<Button x:Name="BtnSearch" Height="120" Width="120" Margin="-20,-30,0,0" Click="BtnSearch_Click" BorderThickness="0" BorderBrush="{x:Null}" Visibility="Visible" >
                <Button.Background>
                    <ImageBrush x:Name="searchImage" ImageSource="images\appbar.feature.search.rest.png" Stretch="Fill"/>
                </Button.Background>

In the above xaml I have to change the imagesource programmatically to a different image. How do I do it ?

A: 

Hi,

An approach you can use is described here. Since your question does not specify the action the code takes to change the background, therefore, you may have to adapt the code in the referred link a bit. Note that you may have to return the ImageBrush from the converter, if you intend to go down the path suggested in the post.

HTH, indyfromoz

indyfromoz
+3  A: 

Use

searchImage.ImageSource =

        new BitmapImage(new Uri(imgPath, UriKind.Relative));

to change the image associated with background image brush.

Vinay B R