对于如下所示的按钮图像,如何更改按钮上的图像来源
<Button Name="btnFullScreen" Width="32" Height="32" Click="BtnFullScreenClick">
<Image Source="img/fs.png" Stretch="Fill"></Image>
</Button>
似乎没有像btnFullscreen.Controls这样的属性(我来自asp.net背景)
答案 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));
}