WPF中资源文件的使用

1、首先添加资源文件到项目:

2

2、设置其属性,将“生成操作”设为“嵌入的资源”。

1

3、代码中的使用:

//相对于程序根目录的资源文件路径

Uri uri = new Uri("/Resources/SqlHelper.txt", UriKind.Relative);

//获取资源文件

StreamResourceInfo info = Application.GetResourceStream(uri);

//读取资源文件

StreamReader s = new StreamReader(info.Stream, Encoding.GetEncoding("gb2312"));

//内容显示到界面

textBox1.Text = s.ReadToEnd();

你可能感兴趣的:(WPF)