【问题标题】:Silverlight Change image source nested inside buttonSilverlight 更改嵌套在按钮内的图像源
【发布时间】:2012-03-21 16:32:58
【问题描述】:

对于像下面这样的按钮图像,我如何在按钮单击时更改图像的来源

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

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

【问题讨论】:

    标签: silverlight xaml button


    【解决方案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));
        }
    

    【讨论】:

    • 内容从来没有闪过我,我在想子控件和其他东西。它只是试图强加尝试简单总是谢谢:)
    猜你喜欢
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    • 2012-02-05
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    相关资源
    最近更新 更多