银光/WP7 : programmatically change the button background image

标签 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>

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

最佳答案

使用

searchImage.ImageSource =

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

更改与背景图像刷关联的图像。

关于银光/WP7 : programmatically change the button background image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3797304/

相关文章:

wcf - 如何使用命令行工具将 .net 4 安装到 IIS

c# - Silverlight + Galasoft MVVM Light + MEF 加载 XAP

windows-phone-7 - 更新绑定(bind)到 Pivot 的 ObservableCollection 在 SelectedIndex >= 2 时崩溃 (wp7)

silverlight - 是否有帮助从 Xaml 中提取可本地化文本的工具?

windows-phone-7 - 您如何让您的 WP7 应用程序显示在游戏中心?

c# - Windows Phone 的 pivot TitleTemplate 中的数据绑定(bind)

C# 在运行时检查 silverlight 对象大小

c# - Silverlight - C# 和 VB.net 事件处理程序之间是否存在性能差异?

c# - Windows Phone 应用程序背景图片

c# - 随机不是那么随机,在 Windows Phone 7 上有随机类