wp7查询天气
来源:互联网 发布:程序员编码规范 编辑:程序博客网 时间:2024/04/30 08:28
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock FontSize="48" x:Name="ApplicationTitle" Text="天气查询" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel>
<TextBlock FontSize="36" Text="请输入城市或地区的名称:"></TextBlock>
<TextBox Name="textBoxCity" Width="439"></TextBox>
<Button Name="buttonQuery" Content="查询" Width="407" Click="buttonQuery_Click"></Button>
<TextBlock FontSize="35" Name="textBlockResult" TextWrapping="Wrap"></TextBlock>
</StackPanel>
</Grid>
</Grid>
//本练习使用的Web Service地址:http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx 记住这里一定要添加引用
//创建客户端实例
ServiceWeather.WeatherWSSoapClient client = new ServiceWeather.WeatherWSSoapClient();
//要查询的城市或地区的名字
string keywords;
//当本页面成为活动页面时触发OnNavigatedTo事件
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
//注册当服务端发回数据时触发的事件
client.getWeatherCompleted += new EventHandler<ServiceWeather.getWeatherCompletedEventArgs>(client_getWeatherCompleted);
//在隔离存储空间中查找是否含有keywords项。这样做主要是为了方便用户,用户一般查询的是当地的天气,输入一次以后就不用输入了。
//当然如果用定位技术,定位手机所在的城市或地区会更好,这里先不涉及定位。
if (IsolatedStorageSettings.ApplicationSettings.Contains("keywords"))
{
//如果含有keywords项,则把该项的值取出来
keywords = IsolatedStorageSettings.ApplicationSettings["keywords"].ToString();
//向服务端发出异步请求,查询天气信息
client.getWeatherAsync(keywords, "");
}
}
//查询按钮点击事件
private void buttonQuery_Click(object sender, RoutedEventArgs e)
{
//把文本框textBoxCity中的值赋给keywords
keywords = textBoxCity.Text;
//向服务端发出异步请求,查询天气信息
client.getWeatherAsync(keywords, "");
}
//得到服务端发回的数据时触发该事件
void client_getWeatherCompleted(object sender, ServiceWeather.getWeatherCompletedEventArgs e)
{
//服务端返回的是一个字符串数组
//可以在这里测试 http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?op=getWeather
string[] result = e.Result;
if (result.Length < 1)
{
textBlockResult.Text = "没有此地的天气信息";
}
else if(result.Length==1)
{
textBlockResult.Text=result[0];
}
else
{
StringBuilder sb = new StringBuilder();
sb.Append(result[1] + "\n");
sb.Append(result[4] + "\n");
sb.Append(result[5] + "\n\n");
sb.Append("今天" + result[7] + "\n");
sb.Append(result[8] + "\n");
sb.Append(result[9] + "\n\n");
sb.Append("明天" + result[12] + "\n");
sb.Append(result[13] + "\n");
sb.Append(result[14] + "\n\n");
sb.Append("后天" + result[17] + "\n");
sb.Append(result[18] + "\n");
sb.Append(result[19] + "\n\n");
textBlockResult.Text = sb.ToString();
IsolatedStorageSettings.ApplicationSettings["keywords"] = keywords;
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
- wp7查询天气
- WP7显示日历天气
- 天气查询
- 天气查询
- 查询天气
- 天气查询
- 天气查询
- 查询天气
- 查询天气
- WP7通过WebService天气服务获取天气信息
- wp7查询公交路线
- PHP天气查询1
- PHP天气查询2
- VB实现天气查询
- AJAX 的天气查询
- 城市天气情况查询
- 根据城市查询天气
- 天气查询接口
- #pragma pack
- 2013第六届辽宁省ACM程序设计竞赛总结+流水账
- URI
- Python Exercise #31
- source code compiled install mongodb
- wp7查询天气
- hugepages
- Core Java Qquestion List No8
- linux 解压缩命令
- 我的学习生涯(Delphi篇) - 17
- wp7查询公交路线
- The Top 10 Movies for Computer Science Students
- strcpy、wcscpy与_tcscpy关系 strcpy_s与strcpy比较
- Android异步加载网络图片