【问题标题】:Imagebutton change source propertyImagebutton 更改源属性
【发布时间】:2011-04-24 12:40:07
【问题描述】:

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

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

<ControlTemplate x:Key="ImageButton" TargetType="Button">
    <Grid>
        <Image Margin="45,8,35,8" Source="Images/Delete.png"/>
    </Grid>
</ControlTemplate>

如何以编程方式更改图像源属性?

【问题讨论】:

    标签: windows-phone-7 custom-controls custom-attributes


    【解决方案1】:

    要更改图像的来源,您需要制作资源的新位图并将其设置为源

    BitmapImage myBitmapImage = new BitmapImage(new Uri("/Images/foo.png", UriKind.Relative));
    
    imageButton.Source = myBitmapImage;
    

    但是我猜你想要一个按钮,如果被点击,它会改变它的背景。您需要重新定义按钮的视觉状态。这是一个例子:

    Windows Phone 7 (WP7) Change a button's background color on click

    【讨论】:

      猜你喜欢
      • 2018-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多