Silverlight 文件资源读取

Silverlight 文件资源读取,第1张

概述使用程序代码加载图片 读取资源的方法:Application.GetResourceStream(Uri uri): StreamResourceInfo Page.xaml文件 <UserControl           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"           xmlns:x="ht

使用程序代码加载图片



读取资源的方法:Application.GetResourceStream(Uri uri): StreamResourceInfo



Page.xaml文件


<UserControl

          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

          x:Class="SilverlightApplication7.Page"

          WIDth="640" Height="480">



          <GrID x:name="LayoutRoot" Background="White">

          </GrID>

</UserControl>




Page.xaml.cs文件


using System;

using System.windows;

using System.windows.Controls;

using System.windows.documents;

using System.windows.Ink;

using System.windows.input;

using System.windows.Media;

using System.windows.Media.Animation;

using System.windows.Shapes;

using System.windows.Resources;

using System.windows.Media.Imaging;



namespace SilverlightApplication7

{

          public partial class Page : UserControl

          {

                   public Page()

                   {

                            // 需要初始化变量

                            InitializeComponent();

            this.MouseleftbuttonDown += new MousebuttonEventHandler(Page_MouseleftbuttonDown);

        }



        voID Page_MouseleftbuttonDown(object sender,MousebuttonEventArgs e)

        {

            Image img = LoadImage("/SilverlightApplication7;component/1150810574.jpg");

            LayoutRoot.Children.Add(img);   

        }

        Image LoadImage(string relativeUrlString)

        {

            Uri uri = new Uri(relativeUrlString,UriKind.relative);

            StreamResourceInfo sri = Application.GetResourceStream(uri);

            BitmAPImage bimg = new BitmAPImage();

            bimg.SetSource(sri.Stream);

            Image img = new Image();

            img.source = bimg;

            return img;

        }

          }

}




使用代码加载文本

Uri uri = new Uri("/SilverlightApplication7;component/remark.txt",UriKind.relative);            StreamResourceInfo sri = Application.GetResourceStream(uri); System.IO.StreamReader reader = new System.IO.StreamReader(sri.Stream); MessageBox.Show(reader.ReadToEnd()); 总结

以上是内存溢出为你收集整理的Silverlight 文件资源读取全部内容,希望文章能够帮你解决Silverlight 文件资源读取所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1069280.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存