本篇为大家介绍 Windows Phone 8.1 中新增的 FlipView 控件,它的中文名字叫做:翻转视图。

虽然听起来有点拗口,但是它的用途大家一定不会陌生。在 Windows Phone 8 中,我们经常会为应用首次启动时加一个引导页,几张引导图片滑动来显示,最后点击确定进入应用。我们会为它写一个控件来实现,而FlipView 可以轻松的完成这一功能。FlipView不止可以作为图片浏览控件,同时还可以作为文本切换,步骤切换等等。下面我们先来看一个简单的例子:

<FlipView>
<TextBlock Text="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="200"/>
<TextBlock Text="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="200"/>
<TextBlock Text="3" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="200"/>
</FlipView>

我们给FlipView添加了三个元素,分别是1,2 和 3。来看看运行效果:
  

如上图中,我们通过水平滑动来显示1,2 和 3,但是不能循环显示,也就是说不能从1向右滑动显示3,或者从3向左滑动显示1。

与其他集合类控件相似,FlipView 支持直接添加元素集合或者将 ItemsSource 绑定到数据源来添加元素。下面我们分别来演示这两种方式:

(1) 直接添加元素集合

<FlipView SelectedIndex="0">
<TextBlock Text="TextBlock" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="70"/>
<Image Source="Assets/setting.png" Width="100"/>
<Border Background="Green" Width="200" Height="200"/>
</FlipView>

我们添加了三个不同类型的元素。同时我们可以通过修改 SelectedIndex 属性来决定初始显示的元素。来看看运行效果:

  

(2) 通过ItemsSource属性绑定

<FlipView x:Name="demoFlipView">
<FlipView.ItemTemplate>
<DataTemplate>
<Grid Background="YellowGreen">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding DemoContent}" FontSize="60"/>
</Grid>
</DataTemplate>
</FlipView.ItemTemplate>
<FlipView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</FlipView.ItemsPanel>
</FlipView>

我们为 FlipView 指定了 ItemTemplate 和 ItemsPanel。其中 ItemsPanel 为纵向排列的 StackPanel,这样我们就可以通过上下滑动的方式来显示元素了。来看看后台代码中的数据绑定:

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
List<Demo> demoList = new List<Demo>();
demoList.Add(new Demo() { DemoContent = "First Item"});
demoList.Add(new Demo() { DemoContent = "Second Item" });
demoList.Add(new Demo() { DemoContent = "Last Item" });
demoFlipView.ItemsSource = demoList;
}
public class Demo
{
public string DemoContent { get; set; }
}

绑定代码很简单,这里不做过多说明,来看看运行效果:

  

上图中,三个元素通过上下滑动的方式显示出来。同样,我们可以利用代码来控制 FlipView 显示哪个元素。比如一个自动浏览的相册,每隔几秒变换一张图片,到最后一张后,重新再来。来看看代码实现:

DispatcherTimer _timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromSeconds(1.0);
_timer.Tick += ((sender, e) =>
{
if (demoFlipView.SelectedIndex < demoFlipView.Items.Count - )
demoFlipView.SelectedIndex++;
else
demoFlipView.SelectedIndex = ;
});
_timer.Start();

如上的代码即可实现 FlipView 的自动切换效果,这里我们不需截图说明了。

好了,到这里我们就把 FlipView 的基本应用介绍完了,希望对大家有帮助,谢谢。

Windows Phone 8.1 新特性 - 控件之FlipView的更多相关文章

  1. Windows Phone 8.1 新特性 - 控件之列表选择控件

    本篇我们来介绍Windows Phone 8.1 新特性中的列表选择控件. 在Windows Phone 8 时代,大家都会使用 LongListSelector 来实现列表选择控件,对数据进行分组显 ...

  2. Windows Phone 8.1 新特性 - 控件之应用程序栏

    2014年4月3日的微软Build 2014 大会上,Windows Phone 8.1 正式发布.相较于Windows Phone 8,不论从用户还是开发者的角度,都产生了很大的变化.接下来我们会用 ...

  3. 与众不同 windows phone (34) - 8.0 新的控件: LongListSelector

    [源码下载] 与众不同 windows phone (34) - 8.0 新的控件: LongListSelector 作者:webabcd 介绍与众不同 windows phone 8.0 之 新的 ...

  4. 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup

    [源码下载] 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup 作者:webabcd 介绍重新想象 Wind ...

  5. 重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame

    [源码下载] 重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame 作者:webabcd 介绍重新想象 Windows 8.1 St ...

  6. 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView

    [源码下载] 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...

  7. 与众不同 windows phone (51) - 8.1 新增控件: DatePickerFlyout, TimePickerFlyout

    [源码下载] 与众不同 windows phone (51) - 8.1 新增控件: DatePickerFlyout, TimePickerFlyout 作者:webabcd 介绍与众不同 wind ...

  8. 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Contract 分享 WebView 中的内容, 为 WebView 截图

    [源码下载] 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Co ...

  9. Windows Phone 8.1新特性 - 应用商店启动协议

    Windows Phone 8.1 Preview SDK 发布也有几个月了,之前断断续续也写过几篇 Windows Phone 8.1 新特性的文章,今天给大家介绍一下应用商店启动协议相关的知识. ...

随机推荐

  1. Spring - constructor-arg和property

    1.说明 constructor-arg:通过构造函数注入.    property:通过setter对应的方法注入. 2.constructor-arg的使用示例 (1).Model代码: 1 2 ...

  2. 关于16年2月14日以后上传AppStore出现:Missing iOS Distribution signing identity for...的问题

    2016年2月14日以后打包上传AppStore会发现出现如下的问题: 导致问题的原因是:下边这个证书过期了 以下是苹果官方给出的回应: Thanks for bringing this to the ...

  3. jQuery easyui combobox获取值|easyui-combobox获取多个值

    Query easyui combobox事例:            name="language"             data-options="        ...

  4. Android调试小技巧(LogCat不输出、Log自动清空、install时timeout)

    问题:有时候明明连接了设备,而LogCat却没有输出 解决方法:在device界面点一下对应设备,使其处于选中状态(它适用于查看手机文件不显示的情况) 问题:前面记录的Log看着看着突然被清空了 解决 ...

  5. Linux如何复制,打包,压缩文件

    (1)复制文件 cp -r  要copy的文件/("/"指的是包括里面的内容)   newfile_name(要命名的文件名) eg:cp -r webapps_zero/   f ...

  6. cefsharp在xp上运行

    今天遇到一个坑.也是自己英语不足的体现.在xp上运行cefsharp.wpf. 查询了各种资料.按照说明一步一步的操作,都没有解决xp上运行cefsharp.wpf. 而且在xp上调试都不知道错误在哪 ...

  7. python autopep8

    安装 使用pip install autopep8或easy_install 都可以. 使用 autopep8 -i -a 要检查的py文件路径 更多参数使用可以参考:https://github.c ...

  8. textArea 高度自适应

    <textarea name="apparatus" class="dhxTextArea" style="width:100%;height: ...

  9. js+html+jquery 个人笔记

    js+html+jquery 笔记 1.获取HTML对象 var obj = document.getElementById(elementId) 对象的值: obj.value() 2.获取jQue ...

  10. BPTT算法推导

    随时间反向传播 (BackPropagation Through Time,BPTT) 符号注解: \(K\):词汇表的大小 \(T\):句子的长度 \(H\):隐藏层单元数 \(E_t\):第t个时 ...