Imagebutton更改源属性 [英] Imagebutton change source property
本文介绍了Imagebutton更改源属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发Windows Phone应用。
I'm developing a Windows Phone app.
我有一个带有图像的自定义按钮。这是它的XAML代码:
I have a custom button with an image inside. This is its XAML code:
<ControlTemplate x:Key="ImageButton" TargetType="Button">
<Grid>
<Image Margin="45,8,35,8" Source="Images/Delete.png"/>
</Grid>
</ControlTemplate>
如何以编程方式更改Image Source属性?
How can I change Image Source property programmatically?
推荐答案
要更改图像的来源,您需要制作资产的新位图并将其设置为源
To change the source of an image you need to make a new bitmap of your asset and set it as a souce
BitmapImage myBitmapImage = new BitmapImage(new Uri("/Images/foo.png", UriKind.Relative));
imageButton.Source = myBitmapImage;
但是我想你想有一个可以改变背景的按钮如果单击。您需要重新定义按钮的视觉状态。这是一个示例:
but I guess you would like to have a button that change its background if is clicked. You need to redefine Visual States of the button. Here is an example:
Windows Phone 7(WP7)更改单击时按钮的背景颜色
这篇关于Imagebutton更改源属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文