简体   繁体   中英

How to include external files when I publish my WPF application?

I'm trying to include .txt files so that I can populate TextBlock controls from them. I'd rather not have huge chunks of my Xaml taken up with extra text.

I've found a solution by using C# to find the text files on disk and set the Text property of the TextBlock s. But when I go to publish the app, I don't think the text file is included. On the Publish tab of the app properties, the text files don't show up there, so I can't select them to include. Do I have to put those files in a specific place in order to be found?

I've tried to create resources from the text files on the Resources tab of the Properties settings, but can't figure out how to access those resources from within C#.

Is there a best practice solution to this? It seems like it should be easy. I may just have to host the text files online and read them from a consistent location.

如果您希望将txt文件与项目一起部署,则可以将txt文件包含到项目中,然后右键单击该文件,单击“属性”,然后在"Copy to Output Directory"指定的属性中"Copy Always""Copy if Newer"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM