【问题标题】:Setting an image.Source from a resource file从资源文件设置 image.Source
【发布时间】:2010-01-29 15:02:42
【问题描述】:
private void SetCredentials()
{
    username = txtfromEmail.Text;
    password = txtpassword.Text;

    pictureLogin.Source = @"C:\Users\Sergio\Documents\Visual Studio 2008\Projects\emailwpf\emailwpf\ok.png";
}

我收到一个错误:"Cannot convert string to ImageSource"

我能做什么?

【问题讨论】:

    标签: c# wpf resources imagesource


    【解决方案1】:

    将源设置为new BitmapImage(new Uri("C:\Users\Sergio\Documents\Visual Studio 2008\Projects\emailwpf\emailwpf\ok.png")) 您可以在 XAML 中设置字符串值,因为在后台使用了注册的转换器;

    【讨论】:

    • 如果我想使用“/ok.png”形式而不是长字符串,我该怎么做呢?
    • 只是创建 Uri 对象,并指定 UriKind.Relative
    猜你喜欢
    • 1970-01-01
    • 2010-11-25
    • 2015-03-20
    • 2010-09-30
    • 1970-01-01
    • 2014-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多