欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

取到数据后不能反绑,propertychangedeventhandler一直替null,求帮助

更新时间: 2014-01-05 02:38:35 责任编辑: Author_N1

 

取到数据后不能反绑,PropertyChangedEventHandler一直为NULL,求帮助

        public class ForecastUpdateState
        {
            public HttpWebRequest AsyncRequest { get; set; }
            public HttpWebResponse AsyncResponse { get; set; }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private string stream;

        public String Stream
        {
            get
            {
                return stream;
            }
            set
            {
                if (value != stream)
                {
                    stream = value;
                    NotifyPropertyChanged("Stream");
                }
            }
        }

        private void NotifyPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }

        public HttpAdapter()
        {
        }

        public void GetStream()
        {
            UriBuilder fullUri = new UriBuilder("http://www.baidu.com");

            // 初始化新的WebRequest
            HttpWebRequest forecastRequest = (HttpWebRequest)WebRequest.Create(fullUri.Uri);

            // 设置状态对象的异步请求
            ForecastUpdateState forecastState = new ForecastUpdateState();
            forecastState.AsyncRequest = forecastRequest;

            // 启动异步请求
            forecastRequest.BeginGetResponse(new AsyncCallback(HandleForecastResponse),
                forecastState);
        }

        private void HandleForecastResponse(IAsyncResult asyncResult)
        {
            // 获得状态信息
            ForecastUpdateState forecastState = (ForecastUpdateState)asyncResult.AsyncState;
            HttpWebRequest forecastRequest = (HttpWebRequest)forecastState.AsyncRequest;

            // 结束异步请求
            forecastState.AsyncResponse = (HttpWebResponse)forecastRequest.EndGetResponse(asyncResult);

            Stream streamResult;
            // 包含异步调用的响应得到的流
            streamResult = forecastState.AsyncResponse.GetResponseStream();


            System.IO.StreamReader reader = new System.IO.StreamReader(streamResult, Encoding.UTF8);


            Deployment.Current.Dispatcher.BeginInvoke(() =>
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:38:35
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/12514/
本文WWW.DOC100.NET DOC100.NET版权所有。