Application.GetContentStream returns null for cont

2019-05-23 11:18发布

I have file "sample.xml" in my project set as content.

I am running this code:

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

Why it returns null contentStream?

标签: c# .net-4.0 uri
2条回答
手持菜刀,她持情操
2楼-- · 2019-05-23 12:01

You must set file's Build Action as Content, and Copy To Output Directory to Copy Always or Copy if newer.

enter image description here

查看更多
太酷不给撩
3楼-- · 2019-05-23 12:06

It means probably that it does not find the file. Is the path correct?.

Return Value

Type: System.Windows.Resources.StreamResourceInfo

A StreamResourceInfo that contains a content data file that is located at the specified Uri. If a loose resource is not found, null is returned.

查看更多
登录 后发表回答