Windows phone 7 Imagebutton更改源属性
我正在开发一个Windows Phone应用程序 我有一个自定义按钮,里面有一个图像。这是它的XAML代码:Windows phone 7 Imagebutton更改源属性,windows-phone-7,custom-controls,custom-attributes,Windows Phone 7,Custom Controls,Custom Attributes,我正在开发一个Windows Phone应用程序 我有一个自定义按钮,里面有一个图像。这是它的XAML代码: <ControlTemplate x:Key="ImageButton" TargetType="Button"> <Grid> <Image Margin="45,8,35,8" Source="Images/Delete.png"/> </Grid> </ControlTemplate>
<ControlTemplate x:Key="ImageButton" TargetType="Button">
<Grid>
<Image Margin="45,8,35,8" Source="Images/Delete.png"/>
</Grid>
</ControlTemplate>
如何以编程方式更改图像源属性?要更改图像源,需要为资源创建新位图并将其设置为源
BitmapImage myBitmapImage = new BitmapImage(new Uri("/Images/foo.png", UriKind.Relative));
imageButton.Source = myBitmapImage;
但是我想您希望有一个按钮,如果单击该按钮,可以更改其背景。您需要重新定义按钮的视觉状态。以下是一个例子:
要更改图像源,您需要为资源创建新位图并将其设置为源
BitmapImage myBitmapImage = new BitmapImage(new Uri("/Images/foo.png", UriKind.Relative));
imageButton.Source = myBitmapImage;
但是我想您希望有一个按钮,如果单击该按钮,可以更改其背景。您需要重新定义按钮的视觉状态。以下是一个例子: