Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 7 Imagebutton更改源属性_Windows Phone 7_Custom Controls_Custom Attributes - Fatal编程技术网

Windows phone 7 Imagebutton更改源属性

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>

我正在开发一个Windows Phone应用程序

我有一个自定义按钮,里面有一个图像。这是它的XAML代码:

<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;
但是我想您希望有一个按钮,如果单击该按钮,可以更改其背景。您需要重新定义按钮的视觉状态。以下是一个例子: