Silverlight/WP7:以编程方式更改按钮背景图像

gfo*_*org 3 silverlight windows-phone-7

<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>
Run Code Online (Sandbox Code Playgroud)

在上面的xaml中,我必须以编程方式将imagesource更改为不同的图像.我该怎么做 ?

Vin*_*B R 6

使用

searchImage.ImageSource =

        new BitmapImage(new Uri(imgPath, UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)

更改与背景图像画笔关联的图像.