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();
        //        }
        //    }

posted @ 2013-01-10 09:38  狄大人  阅读(1388)  评论(0编辑  收藏  举报