首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

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

2013-09-29 
取到数据后不能反绑,PropertyChangedEventHandler一直为NULL,求帮助public class ForecastUpdateState{pub

取到数据后不能反绑,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(() =>


            {
                Stream = reader.ReadToEnd();
            });
        }




        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
           HttpAdapter() ds = new HttpAdapter();
            ds.GetStream();
            DataContext = ds;
            txtName.Text = ds.Stream;
        }


为什么调用的时候 PropertyChanged 一直为NULL,哪里有问题,请帮我看看,指出问题 异步 httpwebrequest PropertyChanged
[解决办法]
PropertyChanged 在哪里初始化的,没有看到。
[解决办法]
PropertyChanged 都没 += 过,当然是null
[解决办法]
你都没注册事件处理程序,不是null就见鬼了。
[解决办法]
引用:
Quote: 引用:

你都没注册事件处理程序,不是null就见鬼了。

帮我看一下在哪注册


 HttpAdapter() ds = new HttpAdapter();
ds.PropertyChanged+=xxxx;
            ds.GetStream();

热点排行