Wpf - relative image source path

后端 未结 4 590
轮回少年
轮回少年 2020-12-01 16:27

I\'m having problems setting the source for images in my Wpf application. I have an Image where the source is bound to the SourceUri property of the DataContext object, like

4条回答
  •  没有蜡笔的小新
    2020-12-01 17:15

    There's a handy method in System.IO.Path which can help with this:

    return Path.GetFullPath("Resources/image.jpg");
    

    This should return 'C:\Folders\MoreFolders\Resources\image.jpg' or whatever the full path is in your context. It will use the current working folder as the starting point.

    Link to MSDN documentation on GetFullPath.

提交回复
热议问题