【发布时间】:2019-10-15 23:48:39
【问题描述】:
我有一个 C# 项目,使用 WPF,带有 dotnet 核心版本 3。我在 Visual Studio 2019 中添加了一个 .PNG 图像,路径为图像/位置,构建操作为“资源”,并复制到“如果较新则复制”的输出。
在 C# 中,我将此图像的相对路径存储在 CurrentLocation 的 ImagePath 属性中。在 WPF 中,我使用了一个图像控件,其中源是对此 ImagePath 属性的绑定。相关代码见文末。
我的问题是图像没有出现,但是当我将 ImagePath 属性中的路径字符串更改为完整/磁盘路径时,确实出现,例如C:\Users\etc,不对底层代码、WPF 控件中的绑定等进行任何其他更改。此外,我 99% 确定我用于获取此图像的相对路径的语法是正确的对于 dotnet 框架,所以我假设这是从框架到核心的功能更改 - 不幸的是,我找不到任何关于此的文档。任何想法发生了什么,或者相对路径如何在 dotnet 核心中起作用?不能用吗?
相关的 C#(ImagePath 属性已定义)
CurrentLocation = new Location
{
Description = "default location description"
,ImagePath = "/simpleRPG_Engine;component/Images/Locations/tempHome.png" // broken???
,Name = "default location"
,XCoordinate = 0
,YCoordinate = 0
};
相关 XAML(ImagePath 属性已绑定)
<Image x:Name = "worldImage"
Grid.Row = "1"
Height = "250"
HorizontalAlignment = "Center"
Source = "{Binding CurrentLocation.ImagePath}"
VerticalAlignment = "Center"
Width = "250"
/>
【问题讨论】:
标签: c# wpf data-binding .net-core wpf-controls