• silverlight读取xml和读取远程文件


                    //读取配置文件
                    XDocument doc = XDocument.Load("config.xml");
                    XElement root = doc.Element("app");
                    baseUrl = root.Element("appurl").Value;

                     //获取远程文件
                     string filePath = "http://www.baidu.com";
                     Uri uri = new Uri(filePath, UriKind.Absolute);
                     WebClient Appclient = new WebClient();//使用WebClient下载config.xml文件,进行异步读取。
                     Appclient.OpenReadAsync(uri);
                     Appclient.OpenReadCompleted += new OpenReadCompletedEventHandler(Appclient_OpenReadCompleted);

             void Appclient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
            {
                Stream stream = e.Result;
                StreamReader reader = new StreamReader(stream);
                string text = reader.ReadToEnd();
                string[] texts = text.Replace(@"\r\n","&").Split('&');
                if (texts != null)
                {
                    for (int i = 0; i < texts.Length; i++)
                    {
                        Paragraph paragraph = new Paragraph() {  LineHeight = 20};
                        Run run = new Run() { Text = texts[i],  FontSize= 12,
                                              FontFamily = new FontFamily("/shendeng.platform.Controls;component/Fonts/simsun.ttc#SimSun")
                        };
                        paragraph.Inlines.Add(run);
                        ZhiNan.Blocks.Add(paragraph);
                    }
                }
            }

           触发HyperlinkButton点击事件
           private HyperlinkButton hlb;
            //    if (hlb != null)
            //    {
            //        HyperlinkButtonAutomationPeer hyperlinkButtonAutomationPeer = new HyperlinkButtonAutomationPeer(hlb);
            //        hyperlinkButtonAutomationPeer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked);
            //        IInvokeProvider iinvoke = (IInvokeProvider)hyperlinkButtonAutomationPeer;
            //        if (iinvoke != null)
            //        {
            //            iinvoke.Invoke();
            //        }
            //    }

  • 相关阅读:
    C# 文件重命名
    C# 获取图像文件
    我开通了博客
    C# 图像截取
    C# 从txt读取内容
    Linux 下查看用户组信息
    部署Jenkins完整记录
    一篇文章搞定Java注解^_^
    Java基础之接口
    枚举让盗版美国总统wcc给你整明白哈哈
  • 原文地址:https://www.cnblogs.com/LYunF/p/2854061.html
Copyright © 2020-2023  润新知