UWP开发---嵌套DataTemplate&模板选择器
对于Json结构体items不完全一致的情况下,在UWP平台是如何处理数据,并通过不同的模板选择,进行显示呢?
一,嵌套Json分析
1,结构
通过抓取index的API(点击请求API)获取到的json,来看主页的数据是嵌套结构的Json,并且在Recs结构体中的items具有不完全一致性,结构如下图:


如上图所示,recs有若干子项,但是展开子项的items即可发现



还有其他就不依依列举图片出来了。
为了让开发工作更加简便,我们可以新建两个类:Hanju,CommonVideo,设置好各类别的各个字段
二,DataTemplate嵌套
①首先最基本的是最低层次的(单个视频,单个韩剧)
韩剧模板(图中那些转换器,宽度不必在意,后续文章会展开来讲)
<DataTemplate x:Key="seriesTemplate">
<Border Margin="2" Width="{Binding ElementName=hanjuThumb_width, Path=Width}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<RelativePanel CornerRadius="10">
<Image x:Name="thumb" Source="{Binding thumb}" HorizontalAlignment="Center" Stretch="UniformToFill"/>
<Image Source="/Assets/Icons/series_preview_icon.png" Visibility="{Binding isPreview,Converter={StaticResource BoolToVisibilityConverter}}" Height="40" RelativePanel.AlignRightWithPanel="True"/>
<Image Source="/Assets/Icons/new_series.png" Visibility="{Binding updateTime,Converter={StaticResource IsNewUpdateConverter}}" Height="40" RelativePanel.AlignRightWithPanel="True"/>
<Image Source="/Assets/Icons/live_ing.png" Visibility="{Binding living,Converter={StaticResource SeriesLivingImgShowConverter}}" RelativePanel.AlignRightWithPanel="True" Height="30"/>
<TextBlock Text="{Binding count}" Foreground="White" RelativePanel.AlignBottomWithPanel="True" RelativePanel.AlignLeftWithPanel="True"/>
<TextBlock Text="{Binding rank}" Foreground="White" RelativePanel.AlignBottomWithPanel="True" RelativePanel.AlignRightWithPanel="True"/>
</RelativePanel>
<TextBlock Grid.Row="2" Text="{Binding name}" HorizontalAlignment="Center" TextWrapping="Wrap" Foreground="Black" FontSize="15"/>
</Grid>
</Border>
</DataTemplate>
韩剧模板
视频模板
<DataTemplate x:Key="videoTemplate">
<Border Margin="2" Width="{Binding ElementName=videoThumb_width,Path=Width}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Image Source="{Binding thumb}" Stretch="UniformToFill"/>
<TextBlock Grid.Row="2" Text="{Binding title}" TextTrimming="WordEllipsis" Foreground="Black" FontSize="15" TextWrapping="Wrap"/>
</Grid>
</Border>
</DataTemplate>
视频模板
直播模板
<DataTemplate x:Key="liveTemplate">
<RelativePanel Width="{Binding ElementName=videoThumb_width,Path=Width}">
<Image Source="{Binding thumb}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<Image Source="/Assets/Icons/star_living.png" Width="50" Margin="5" RelativePanel.AlignRightWithPanel="True"/>
<TextBlock Text="{Binding longTitle}" Foreground="White" RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignBottomWithPanel="True"/>
<TextBlock Text="{Binding online}" Foreground="White" RelativePanel.AlignRightWithPanel="True" RelativePanel.AlignBottomWithPanel="True"/>
</RelativePanel>
</DataTemplate>
直播模板
②其次是高一层次的模板,上述模板是下列这些的子项(整个韩剧集合,整个视频分类集合,GridView从左往右放单个视频)
<!--模板1韩剧-->
<DataTemplate x:Key="DataTemplate1">
<GridView IsItemClickEnabled="True" ItemClick="Hanju_ItemClick" Header="{Binding title,Converter={StaticResource StringFormatConverter},ConverterParameter='
UWP开发---嵌套DataTemplate&模板选择器的更多相关文章
- UWP开发必备:常用数据列表控件汇总比较
今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ...
- win10 uwp 列表模板选择器
本文主要讲ListView等列表可以根据内容不同,使用不同模板的列表模板选择器,DataTemplateSelector. 如果在 UWP 需要定义某些列的显示和其他列不同,或者某些行的显示和其他行不 ...
- UWP开发笔记——嵌套式页面的实现
绪论 UWP开发中,Page是最常用的Control之一,通常情况下,在开发的application中,每一个页面就是一个Page.有时候,为了开发整合度更高,UI表现更为一致的UI,开发者需要把UI ...
- 【转】wpf 模板选择器DataTemplateSelector及动态绑定,DataTemplate.Triggers触发器的使用
通常,如果有多个 DataTemplate 可用于同一类型的对象,并且您希望根据每个数据对象的属性提供自己的逻辑来选择要应用的 DataTemplate,则应创建 DataTemplateSelect ...
- wpf 模板选择器DataTemplateSelector及动态绑定,DataTemplate.Triggers触发器的使用
通常,如果有多个 DataTemplate 可用于同一类型的对象,并且您希望根据每个数据对象的属性提供自己的逻辑来选择要应用的 DataTemplate,则应创建 DataTemplateSelect ...
- 2019-11-29-win10-uwp-列表模板选择器
原文:2019-11-29-win10-uwp-列表模板选择器 title author date CreateTime categories win10 uwp 列表模板选择器 lindexi 20 ...
- 2019-9-2-win10-uwp-列表模板选择器
title author date CreateTime categories win10 uwp 列表模板选择器 lindexi 2019-09-02 12:57:38 +0800 2018-2-1 ...
- Win10 UWP开发系列:使用VS2015 Update2+ionic开发第一个Cordova App
安装VS2015 Update2的过程是非常曲折的.还好经过不懈的努力,终于折腾成功了. 如果开发Cordova项目的话,推荐大家用一下ionic这个框架,效果还不错.对于Cordova.PhoneG ...
- Win10/UWP开发—使用Cortana语音指令与App的前台交互
Win10开发中最具有系统特色的功能点绝对少不了集成Cortana语音指令,其实Cortana语音指令在以前的wp8/8.1时就已经存在了,发展到了Win10,Cortana最明显的进步就是开始支持调 ...
随机推荐
- 6-Qt给父widget加上styleSheet(添加背景图)而不改变子widget的styleSheet的方法
Qt给父widget加上styleSheet(添加背景图)而不改变子widget的styleSheet的方法 比如用stylesheet给widget加背景图,可以用qt designer修改ui文件 ...
- 绑定服务-----------binderService TimerTask的使用
绑定服务 服务中通过定义Binder对象的子类让这个子类成为桥梁 在onBind()中返回子类对象 这样就可以在activity中调用这个子类的方法 在Activity中通过ServiceConn ...
- 在windows系统下安装oracle 11g
oracle 11g 安装在windows server 2012 系统下. 最近,需要配置数据库,要求在windows操作系统下,安装oracle 11g 数据库,因为以前没有安装过,所以成功后, ...
- git 记住用户名和密码
git 记住用户名和密码 在使用 git 时,如果用的是 HTTPS 的方式,则每次提交,都会让输入用户名和密码,久而久之,就会感觉非常麻烦,那么该如何解决呢? 1. 使用 SSH,添加 ssh ke ...
- ubuntu16.04 LTS Server 安装mysql phpmyadmin apache2 php5.6环境
1.安装apache sudo apt-get install apache2 为了测试apache2是否正常,访问http://localhost/或http://127.0.0.1/,出现It W ...
- 使用java做paypal开发时购买东西支付不成功的原因
使用java做paypal开发时购买东西支付不成功的原因 没有设置网站习惯设定,登陆自己的paypal账户,在网站习惯设定上填写回调的url路径,这样就可以 支付成功了并且异步修改订单的状态. 支付成 ...
- 一致性哈希Java源码分析
首次接触一致性哈希是在学习memcached的时候,为了解决分布式服务器的负载均衡或者说选路的问题,一致性哈希算法不仅能够使memcached服务器被选中的概率(数据分布)更加均匀,而且使得服务器的增 ...
- python编码(六)
1. 字符编码简介 1.1. ASCII ASCII(American Standard Code for Information Interchange),是一种单字节的编码.计算机世界里一开始只有 ...
- C#-流、存储
流输入输出 VS提供的类库,可方便数据的转移操作,一部分是文件和目录方面 file类 用静态方法, fileinfo类 用实例方法 dictionary类 用静态方法 dictionary ...
- 关于React的入门级安装和最浅显解释
春节临近,办公室里半片空位,半片浮嚣. 想到将放假,屏幕上的代码也都变成了雀跃的小虫. 无法专心了. 终于还是强迫自己读了半篇文档,写了几坨程序. 这次记录的是关于React,最浅显的内容. ———— ...