开发者

Silverlight/WP7: programmatically change the button background image

开发者 https://www.devze.com 2023-01-17 10:16 出处:网络
<Button x:Name=\"BtnSearch\" Height=\"120\" Width=\"120\" Margin=\"-20,-30,0,0\" Click=开发者_运维百科\"BtnSearch_Click\" BorderThickness=\"0\" BorderBrush=\"{x:Null}\" Visibility=\"Visible\" >
<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 ?


Use

searchImage.ImageSource =

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

to change the image associated with background image brush.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消