If a folder content is added to the SilverlightApplication6 project, a mxh.txt file and mxh.jpg are placed below, and the contents of the file are freely written. In the file properties of Solution Explorer, set "Build Action" to "Content"; The Copy to Output Directory property is set to does not copy.
In the XAML file, enter:
XAML Code
<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 Content Input:
C # code
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 ();
Reading text
StreamResourceInfo r = Application.getresourcestream (new Uri ("Content/mxh.txt", urikind.relative));
StreamReader sr = new StreamReader (r.stream);
Textboxname.text = Sr. ReadToEnd ();
Sr. Dispose ();
Show build Action as Content picture
R = Application.getresourcestream (new Uri ("Content/mxh.jpg", urikind.relative));
BitmapImage bmp1 = new BitmapImage ();
Bmp1. SetSource (R.stream);
Imagenameincude.source = BMP1;
Show build Action for Resource picture
R = Application.getresourcestream (new Uri ("Silverlightapplication6;component/content/mxh2.jpg", UriKind.Relative)) ;
BitmapImage bmp2 = new BitmapImage ();
Bmp2. SetSource (R.stream);
Imagenameembed.source = BMP2;
}
}
}
Press F5 to compile the preview to see the contents of the Mxh.txt file in the TextBox and the photos showing the Mengxian.
Note: the delimiter "; component/" is required.
Also, note that the name of the assembly is used in the code SILVERLIGHTAPPLICATION6.