以前写过一个wp8的工程,说实话那会的代码很麻烦,写起来费劲,另外还没多少人下载,不过到windows 10 开始微软出了UWP架构以后一切都像以前的winform wpf一样好转起来,新建一个工程以后模板很简洁。

现在就开始介绍一下基本控件的使用,为新手写程序提供一个例子。7天酒店没有官方客户端,不过不妨碍拿他做例子。

  由于以前代码使用到了json.net 为了减少代码修改,所以还是需要引入进来,但去官方网站下载的无法直接使用,说什么不适配,只要打开

然后呢搜索Json  其实我打开默认第二个就是

添加好之后呢

开始布局代码

在MainPage.xaml中写如下代码

<Pagex:Class="_7inns.MainPage"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using:_7inns"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"><Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"><Grid.Resources><CollectionViewSource x:Name="itemcollectSource" IsSourceGrouped="true" ItemsPath="ItemContent" /></Grid.Resources><Image Source="Assets/2.png" Margin="42,23,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="109" Width="94" /><TextBlock Margin="42,193,264,0" TextWrapping="Wrap" Text="城市" VerticalAlignment="Top" FontSize="20" FontWeight="Bold"/><TextBlock Margin="42,252,264,0" TextWrapping="Wrap" Text="区域" VerticalAlignment="Top" FontSize="20" FontWeight="Bold"/><Button x:Name="buttonCities" Content="" HorizontalAlignment="Stretch" Margin="104,194,3,0" VerticalAlignment="Top" Click="buttonCities_Click" BorderThickness="1" Height="33"/><SemanticZoom x:Name="semanticZoomCities" Margin="0" ViewChangeCompleted="SemanticZoom_ViewChangeCompleted" Visibility="Collapsed" Canvas.ZIndex="5" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"><SemanticZoom.ZoomedInView><ListView x:Name="ListCities" ScrollViewer.IsHorizontalScrollChainingEnabled="False" ScrollViewer.IsVerticalScrollChainingEnabled="False" ItemClick="ListCities_ItemClick" SelectionChanged="ListCities_SelectionChanged"><ListView.GroupStyle><GroupStyle><GroupStyle.HeaderTemplate><DataTemplate><Border Background="#FFECAE0A" Height="60" Width="60"><TextBlock Text="{Binding Key}" FontSize="50" Foreground="{ThemeResource ApplicationForegroundThemeBrush}"></TextBlock></Border></DataTemplate></GroupStyle.HeaderTemplate></GroupStyle></ListView.GroupStyle><ListView.ItemTemplate><DataTemplate><StackPanel><TextBlock Text="{Binding name}" Height="40" FontSize="30"></TextBlock></StackPanel></DataTemplate></ListView.ItemTemplate></ListView></SemanticZoom.ZoomedInView><SemanticZoom.ZoomedOutView><GridView x:Name="GridCitiesFirstName" ScrollViewer.IsHorizontalScrollChainingEnabled="False" ScrollViewer.IsVerticalScrollChainingEnabled="False" Margin="0,100" HorizontalAlignment="Center" VerticalAlignment="Center"><GridView.ItemTemplate><DataTemplate><Border Height="60"><TextBlock Text="{Binding Group.Key}" FontSize="24"></TextBlock></Border></DataTemplate></GridView.ItemTemplate><GridView.ItemsPanel><ItemsPanelTemplate><WrapGrid ItemWidth="60" ItemHeight="60" VerticalChildrenAlignment="Center" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" /></ItemsPanelTemplate></GridView.ItemsPanel><GridView.ItemContainerStyle><Style TargetType="GridViewItem"><Setter Property="BorderBrush" Value="Gray" /><Setter Property="Background" Value="#FFECAE0A" /><Setter Property="BorderThickness" Value="3" /><Setter Property="HorizontalContentAlignment" Value="Center" /><Setter Property="VerticalContentAlignment" Value="Center" /></Style></GridView.ItemContainerStyle></GridView></SemanticZoom.ZoomedOutView></SemanticZoom><ComboBox x:Name="comboBoxDistricts" Margin="107,251,0,0" VerticalAlignment="Top" BorderThickness="1" SelectionChanged="comboBoxDistricts_SelectionChanged" Width="251"/><TextBlock Margin="42,368,264,0" TextWrapping="Wrap" Text="关键字" VerticalAlignment="Top" FontSize="20" FontWeight="Bold"/><TextBlock Margin="42,442,264,0" TextWrapping="Wrap" Text="入住时间" VerticalAlignment="Top" FontSize="20" FontWeight="Bold"/><Button x:Name="search" Content="搜索" HorizontalAlignment="Right" Margin="0,0,10,49" VerticalAlignment="Bottom" Click="search_Click" FontSize="20" FontWeight="Bold" BorderThickness="1" RenderTransformOrigin="0.925,0.455" Width="129"/><DatePicker x:Name="inRoomDate" Margin="96,454,0,0" VerticalAlignment="Top" DateChanged="inRoomDate_DateChanged" BorderThickness="1" Width="255"/><TextBox x:Name="keyword" Margin="104,358,1,0" TextWrapping="Wrap" VerticalAlignment="Top"/></Grid>
</Page>

恕当时没什么布局概念,基本就是手动布局,罗列控件。布局的事情以后再慢慢写,不过微软的教程或者其他书里面这块讲的很清楚,各种panel grid 布局。

这个里面基本就是一些textblock 跟textbox button 和一个SemanticZoom  SemanticZoom的效果就是联系人菜单那个感觉,这里用来选择城市

先看一下选择前的

点一下字母 就会有

然后可以选个北京

后台呢就会对这个选择的city进行行政区查询

        private async void ListCities_SelectionChanged(object sender, SelectionChangedEventArgs e){Debug.WriteLine("ListCities_SelectionChanged");if (e.AddedItems.Count == 1){currentCityItem = (CityItem)e.AddedItems.First();Debug.WriteLine(currentCityItem.name);buttonCities.Content = currentCityItem.name;}string di = await FindDistrict(currentCityItem.id);int total = di.Length;semanticZoomCities.Visibility = Visibility.Collapsed;if (total <= 6)return;JArray jobjectAllDistricts = JArray.Parse(di);comboBoxDistricts.PlaceholderText = "";comboBoxDistricts.Items.Clear();if (DItem != null){DItem.Clear();for (int i = 0; i < jobjectAllDistricts.Count; i++){DItem.Add(new DistrictItem { id = (string)jobjectAllDistricts[i]["id"], name = (string)jobjectAllDistricts[i]["name"] });//Debug.WriteLine((string)jobjectAllDistricts[i]["name"]);
comboBoxDistricts.Items.Add((string)jobjectAllDistricts[i]["name"]);}}Debug.WriteLine("Total bytes returned:  " + total);}

FindDistrict这个函数就需要用到http请求了

当时这么写的 可能是win10推荐的代码 不过能用
        private async Task<string> FindDistrict(string id){string url = @"http://m.7daysinn.cn/q/city/" + id + @"/districts";HttpClientHandler handler = new HttpClientHandler();handler.AllowAutoRedirect = false;HttpClient httpClient = new HttpClient(handler);// Limit the max buffer size for the response so we don't get overwhelmed
httpClient.MaxResponseContentBufferSize = 256000;string result;try{result = await httpClient.GetStringAsync(url);return result;}catch (Exception){}return "";}

点击搜索按钮就可以得到这个日子的酒店列表啦
        private async void search_Click(object sender, RoutedEventArgs e){try{string url = @"http://m.7daysinn.cn/q/inns?cityId=" + currentCityItem.id;if (currentDistrictItem != null && currentDistrictItem.id != ""){url += "&districtId=";url += currentDistrictItem.id;}if (keyword.Text != ""){url += "&keyword=";url += Uri.EscapeUriString(keyword.Text);}url += "&fromDate=" + inDate.Date.ToString("yy-MM-dd") + "&days=1&getQuota=true";HttpClientHandler handler = new HttpClientHandler();handler.AllowAutoRedirect = false;HttpClient httpClient = new HttpClient(handler);// Limit the max buffer size for the response so we don't get overwhelmed
httpClient.MaxResponseContentBufferSize = 256000;ParameterObject po = new ParameterObject();po.result = await httpClient.GetStringAsync(url);po.date = inDate;Frame.Navigate(typeof(InnStatus), po);}catch (Exception){}}

Frame.Navigate(typeof(InnStatus), po);这句呢就是把数据传到第二个页面

第二个页面Innstatus 解析并且展示出来
 protected override void OnNavigatedTo(NavigationEventArgs e){innstatus = (ParameterObject)e.Parameter;try{List<InnItem> innItems = new List<InnItem>();JObject jobjectAllInns = JObject.Parse(innstatus.result);JArray jaRooms = (JArray)jobjectAllInns["content"];for (int i = 0; i < jaRooms.Count; i++){innItems.Add(new InnItem{innId = (string)jaRooms[i]["innId"],name = (string)jaRooms[i]["name"],firstCharsOfPinyin = (string)jaRooms[i]["firstCharsOfPinyin"],cityId = (string)jaRooms[i]["cityId"],cityName = (string)jaRooms[i]["cityName"],districtId = (string)jaRooms[i]["districtId"],districtName = (string)jaRooms[i]["districtName"],address = (string)jaRooms[i]["address"],score = (string)jaRooms[i]["score"],orderWeight = (string)jaRooms[i]["orderWeight"],thumbnailPath = (string)jaRooms[i]["thumbnailPath"],lowestPrice = (string)jaRooms[i]["lowestPrice"],hasRoom = (string)jaRooms[i]["hasRoom"],hasWifi = (string)jaRooms[i]["hasWifi"],hasPark = (string)jaRooms[i]["hasPark"],canUseCashCoupon = (string)jaRooms[i]["canUseCashCoupon"],brandId = (string)jaRooms[i]["brandId"],//currentActivities = (string)jaRooms[i]["currentActivities"],
                    });}this.inncollectSource.Source = innItems;ContentInnsList.ItemsSource = inncollectSource.View;}catch (Exception){ }}

效果如下

 
第二个页面的xaml代码就这么写的一个数据模板
<Pagex:Class="_7inns.InnStatus"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using:_7inns"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"><Grid x:Name="LayoutRoot"><Grid.ChildrenTransitions><TransitionCollection><EntranceThemeTransition/></TransitionCollection></Grid.ChildrenTransitions><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="*"/></Grid.RowDefinitions><!-- TitlePanel --><StackPanel Grid.Row="0" Margin="0" Orientation="Horizontal"><TextBlock Text="酒店状态" Style="{ThemeResource TitleTextBlockStyle}" Typography.Capitals="SmallCaps" Margin="0,15,0,16.5" RenderTransformOrigin="1.473,0.155" Width="300" TextAlignment="Center"/></StackPanel><!--TODO: Content should be placed within the following grid--><Grid Grid.Row="1" x:Name="ContentRoom"><Grid.Resources><CollectionViewSource x:Name="inncollectSource" IsSourceGrouped="False" ItemsPath="" /></Grid.Resources><ListView x:Name="ContentInnsList" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" IsItemClickEnabled="True" ItemClick="ContentInnsList_ItemClick"><ListView.ItemTemplate><DataTemplate><StackPanel><TextBlock Text="{Binding name}" Height="40" FontSize="30"></TextBlock><TextBlock Text="{Binding address}" Height="30" FontSize="14" Foreground="#FFECAE0A"></TextBlock></StackPanel></DataTemplate></ListView.ItemTemplate></ListView></Grid></Grid>
</Page>

好啦 要介绍的就这么多

工程我上传上来好了方便新手调试

http://files.cnblogs.com/files/emsoro/7inns.zip

 

转载于:https://www.cnblogs.com/emsoro/p/5134723.html

UWP入门一 7天酒店客户端源码及说明相关推荐

  1. maven快速入门番外篇——Eclipse下载GitHub上FastDFS-Client客户端源码并转化成maven工程以及打包到本地maven仓库

    由于fastdfs-client的jar包目前在中央仓库是没有坐标的,而在项目中要想实现文件的上传和下载就得使用到它,这不禁就让我们头疼,所以为了解决这个问题,我写下了这篇文章,希望对读者能有所帮助. ...

  2. boost::asio异步模式的C/S客户端源码实现

    异步模式的服务器源码 //g++ -g async_tcp_server.cpp -o async_tcp_server -lboost_system //#include <iostream& ...

  3. zookeeper 客户端_zookeeper进阶-客户端源码详解

    流程图 先看一下客户端源码的流程图 总体流程 总体流程 开启SendThread线程 开启EventThread 总结 下面根据源码讲解,大家整合源码和流程图一起看最好,本篇内容比较多建议收藏起来看. ...

  4. grpc-go客户端源码分析

    grpc-go客户端源码分析 代码讲解基于v1.37.0版本. 和grpc-go服务端源码分析一样,我们先看一段示例代码, const (address = "localhost:50051 ...

  5. 推荐免费下载大型酒店管理系统源码

    推荐免费下载大型酒店管理系统源码 下载地址:http://www.hur.cn/tg/linkin.asp?linkid=194606 下载地址:[URL=http://www.hur.cn/tg/l ...

  6. RabbitMQ初步到精通-第十章-RabbitMQ之Spring客户端源码

    目录 第十章-RabbitMQ之Spring客户端源码 1. 前言 2. 客户端消费代码 2.1 消费的实现方式 2.2 消费中注解解释 2.3 推测Spring实现过程 3.MQ消费源码分析 3.1 ...

  7. WordPress Blog Android客户端源码分析(一)

    一直想找一个大型的Android开源项目进行分析,由于自身和导师课程需要选择了wordpress的Android客户端源码进行学习和解读.源码github官方下载地址:开源项目地址.分析源码的最佳手段 ...

  8. 使用live555客户端源码遇到的问题及解决方法

    使用live555客户端源码拉rtsp流遇到两个问题,正常测试拉取海康摄像头没问题: 1.拉有些厂商的rtsp流会间隔一段时间断开连接: 2.与大华摄像头建立连接时,发送DESCRIBE命令后很长时间 ...

  9. RabbitMQ 客户端源码系列 - Channel

    前言 续上次分享 RabbitMQ 客户端源码系列 - Connection ,继续分享Channel相关的源码分析 (com.rabbitmq:amqp-client:4.8.3) 友情提醒:本次分 ...

最新文章

  1. Ubuntu下对双显卡的支持问题
  2. POJ 2389 Bull Math(水~Java -大数相乘)
  3. C++遍历树-非递归递归-使用了标记位
  4. MySQL数据库储存引擎Inoodb一--记录储存结构
  5. 将截断字符串或二进制数据。
  6. JAVA实现随机无重复数字功能
  7. 雅马哈发电机换机油教程_康明斯柴油发电机组怠速一会就自动停机是什么故障...
  8. stm32cubeIDE下载无法打开GDB的问题
  9. 这样选择报表系统,才能更好的进行企业管理
  10. 用matlab做bp神经网络预测,matlab人工神经网络预测
  11. 我的世界服务端java路径_我的世界服务端java路径咋样设置?
  12. 基于Unity3d的FPS与塔防相结合的游戏设计
  13. 忆我的大学老师----(一)
  14. 聊聊 Docker 的存储驱动 Overlay2
  15. 12.30天自动登陆
  16. Vue+Element动态生成新表单并添加验证
  17. 安装一个新的int 9中断例程【在DOS下,按Tab建后改变当前屏幕的显示颜色,其它键照常处理】...
  18. python界面设计-文件操作excel读写-发动机激励、悬置系统模态及振动计算
  19. 26.看前端视频的感悟,来自碎碎念记录
  20. Matlab—微积分运算

热门文章

  1. liunx 常用操作
  2. 请还未提交实名的博客专家在8月4日前尽快提交您的实名信息
  3. 如何关联php5与apche,PHP5在Apache下的两种模式的安装_php
  4. 蓝桥杯 ALGO-105 算法训练 黑色星期五
  5. “高级”CSS样式一般应用于控制网页内容的外观。附加样式表分为内嵌样式表和外部样式表两种方式。
  6. 【解释】while(~scanf(%d, n))的~的含义~scanf
  7. 1024. 科学计数法 (20)-PAT乙级真题
  8. 蓝桥杯 ADV-68算法提高 企业奖金发放
  9. python爬虫requests库_python爬虫使用Requests库 - pytorch中文网
  10. Eclipse 安装 Fatjar.jar失败的解决方法