Silverlight/WP7: 编程更改按钮背景图片

3
<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中,我需要以编程方式将图像源更改为不同的图像。 我该怎么做?
2个回答

6
使用
searchImage.ImageSource =

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

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

1
@ Vinay 但是使用这段代码后,当按钮被点击时,我将按钮的颜色设置为透明。 - Sujiz

1
你可以采用的方法是在这里描述。由于你的问题没有指定代码执行更改背景的操作,因此你可能需要稍微调整引用链接中的代码。请注意,如果你打算按照帖子中建议的方式进行操作,则可能需要从转换器返回ImageBrush。

希望对你有所帮助, indyfromoz


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接