Silverlight读取嵌入在xap文件中的文件内容
2012-11-06 16:31
288 查看
在 xaml 文件中输入:
XAML 代码
<UserControl x:Class="SilverlightApplication6.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600"> <Grid x:Name="LayoutRoot" Background="White"> <Canvas Width="800" Height="600"> <TextBox x:Name="TextBoxName" Height="30" Canvas.Top="10"></TextBox> <Image x:Name="ImageNameIncude" Canvas.Top="60" Height="200"></Image> <Image x:Name="ImageNameEmbed" Canvas.Top="260" Height="100"></Image> </Canvas> </Grid> </UserControl>
xaml.cs 内容输入:
C# 代码
using System; using System.Windows; using System.Windows.Media.Imaging; using System.Windows.Controls; using System.IO; using System.Windows.Resources; namespace SilverlightApplication6 { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); // 读取文字 StreamResourceInfo r = Application.GetResourceStream(new Uri("Content/mxh.txt", UriKind.Relative)); StreamReader sr = new StreamReader(r.Stream); TextBoxName.Text = sr.ReadToEnd(); sr.Dispose(); //显示 Build Action 为 Content 图片 r = Application.GetResourceStream(new Uri("Content/mxh.jpg", UriKind.Relative)); BitmapImage bmp1 = new BitmapImage(); bmp1.SetSource(r.Stream); ImageNameIncude.Source = bmp1; //显示 Build Action 为 Resource 图片 r = Application.GetResourceStream(new Uri("SilverlightApplication6;component/Content/mxh2.jpg", UriKind.Relative)); BitmapImage bmp2 = new BitmapImage(); bmp2.SetSource(r.Stream); ImageNameEmbed.Source = bmp2; } } }
按F5进行编译预览,即可在 TextBox 中看到 mxh.txt文件的内容和显示孟宪会的照片。
注意:分隔符“;component/”是必须的。
另外,注意代码中使用了程序集的名字 SilverlightApplication6。
相关文章推荐
- Silverlight读取嵌入在xap文件中的文件内容
- 把项目中的xml文件的生成操作改为“嵌入的资源”,我在这个项目中怎么读取xml文件里的内容?
- 读取silverlight程序形成的xap包中的文件
- java自动根据文件内容的编码来读取避免乱码
- win32+QT 实现exe中执行返回的网页内容重定向到txt文件,根据需求读取里面内容
- 使用ifstream和getline读取文件内容
- 实现快速读写配置文件的内容,可以用于读取*.exe.config文件或者Web.Config文件的内容,或者可以读取指定文件的配置项.
- python实现对csv文件的列的内容读取
- 读取msi文件内容
- Java读取文件内容到byte[]数组中
- 01- - -1.获得项目中info.plist文件的内容 2.沙盒的数据存储及读取 3.控制器view的高度和状态栏statusBar的关系 4.[UIScreen mainScreen].applicationFrame的取值 5.按钮的状态 6.错误调试技巧 7.按钮的各种状态设置
- 从文件中读取内容设置为对象的方法
- js创建并读取txt文件的内容
- 文件上传-队列多线程读取文件内容
- PHP读取Excel文件内容
- 学习ThinkPHP3.2.2:video9,用“C”函数读取配置文件内容
- Excel VBA 循环读取一个目录下面多个文件的内容,放到另外一个文件中
- java读取txt文件内容,存放到list的方法
- Java——读取properties文件内容
- MFC中读取文件内容