从资源文件设置image.Source

Ser*_*pia 5 c# wpf resources imagesource

private void SetCredentials()
{
    username = txtfromEmail.Text;
    password = txtpassword.Text;

    pictureLogin.Source = @"C:\Users\Sergio\Documents\Visual Studio 2008\Projects\emailwpf\emailwpf\ok.png";
}
Run Code Online (Sandbox Code Playgroud)

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

我能做什么?

Yur*_*kyy 7

set source to new BitmapImage(new Uri("C:\Users\Sergio\Documents\Visual Studio 2008\Projects\emailwpf\emailwpf\ok.png")) 你可以在XAML中设置为字符串值,因为注册转换器是在引擎盖下使用的;