Application.GetContentStream为内容Uri返回null

我在项目集中将“sample.xml”文件作为内容。

我正在运行此代码:

Uri uri = new Uri("/sample.xml", UriKind.Relative); StreamResourceInfo contentStream = Application.GetContentStream(uri); 

为什么它返回null contentStream?

这可能意味着它找不到文件。 路径是否正确?

回报价值

键入:System.Windows.Resources.StreamResourceInfo

StreamResourceInfo,包含位于指定Uri的内容数据文件。 如果找不到松散的资源,则返回null。

您必须将文件的Build Action设置为内容, Copy To Output DirectoryCopy Always Copy if newerCopy if newer

在此处输入图像描述