Silverlight更改图像源嵌套在按钮内

时间:2012-03-21 03:51:40

标签: silverlight xaml button

对于如下所示的按钮图像,如何更改按钮上的图像来源

    <Button Name="btnFullScreen" Width="32" Height="32" Click="BtnFullScreenClick">
        <Image Source="img/fs.png" Stretch="Fill"></Image>
    </Button>

似乎没有像btnFullscreen.Controls这样的属性(我来自asp.net背景)

1 个答案:

答案 0 :(得分:1)

您拥有Content财产。

private void BtnFullScreenClick(object sender, System.Windows.RoutedEventArgs e)
    {
        Image img = ((Button)sender).Content as Image;
        img.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("newImage.jpg", System.UriKind.Relative));
    }