Silverlight / WP7: programmatically change the background image of a button

<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 programmatically change the image source code to another image. How should I do it?

+3
source share
2 answers

The approach you can use is described here . Since your question does not indicate the action that the code takes to change the background, you may have to adapt the code a little in the link mentioned. Please note that you may need to return ImageBrush from the converter if you intend to follow the path suggested in the message.

NTN, indyfromoz

+1
source

Use

searchImage.ImageSource =

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

, .

+6

Source: https://habr.com/ru/post/1766618/


All Articles