取到数据后不能反绑,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;
}