【问题标题】:Programmatically set the background of a button to be an image以编程方式将按钮的背景设置为图像
【发布时间】:2012-01-20 10:25:00
【问题描述】:

如何以编程方式将按钮的背景设置为图像? 我知道如何在 XAML 中做到这一点,但在代码中,我一直卡住,我试过了

Button.Background = new ImageBrush{ ImageSource = "source" };

然后我得到了字符串无法转换为 ImageSource 的错误。

【问题讨论】:

    标签: windows-phone-7 button imagesource


    【解决方案1】:
    Try:
    Button.Background = new ImageBrush{ ImageSource = new BitmapImage(new Uri(imgPath, UriKind.Relative)) };
    

    【讨论】:

    • Thx =3 我已经找到了答案:Background = new ImageBrush { ImageSource = ( ImageSource ) new ImageSourceConverter( ).ConvertFromString( "source" ) }
    • +1 注意:如果图片来自互联网,那么我们必须使用绝对。
    猜你喜欢
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多