[源码下载]

与众不同 windows phone (50) - 8.1 新增控件: PickerFlyout, ListPickerFlyout

作者:webabcd

介绍
与众不同 windows phone 8.1 之 新增控件

  • PickerFlyout - 选取器控件
  • ListPickerFlyout - 列表选取器控件

示例
1、演示 PickerFlyout 的应用
PickerFlyoutDemo.xaml

<Page
x:Class="Demo.Control.PickerFlyoutDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Demo.Control"
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>
<StackPanel Orientation="Vertical"> <!--xaml 方式弹出选取器控件-->
<Button Content="Show Picker" >
<Button.Flyout>
<PickerFlyout ConfirmationButtonsVisible="True" Confirmed="PickerFlyout_Confirmed" Closed="PickerFlyout_Closed">
<TextBlock Text="Xbox One集全方位娱乐及游戏大作于一身的综合娱乐设备,让您在各个区间轻松跳转.让您在游戏,娱乐及在线视频间轻松跳转"
FontSize="30" Margin="0 20 0 0" TextWrapping="Wrap" />
</PickerFlyout>
</Button.Flyout>
</Button> <!--非 xaml 方式弹出选取器控件-->
<Button Name="button" Content="Show Picker" Click="button_Click_1" Margin="0 10 0 0" /> <TextBlock Name="lblMsg" Margin="0 10 0 0" /> </StackPanel>
</Grid>
</Page>

PickerFlyoutDemo.xaml.cs

/*
* PickerFlyout - 选取器控件(wp only)
* ConfirmationButtonsVisible - 是否显示按钮(一个确认按钮,一个取消按钮),不显示的话则只能通过“返回键”返回
* Content - 选取器控件显示的内容
*
* ShowAtAsync(FrameworkElement target) - 弹出选取器控件
* Hide() - 隐藏弹出框
*
* Confirmed - 点击确认按钮后触发的事件
* Opening, Opened, Closed - 几个顾名思义的事件
*/ using System;
using Windows.UI.Xaml.Controls; namespace Demo.Control
{
public sealed partial class PickerFlyoutDemo : Page
{
public PickerFlyoutDemo()
{
this.InitializeComponent();
} private void PickerFlyout_Confirmed(PickerFlyout sender, PickerConfirmedEventArgs args)
{
lblMsg.Text += "confirmed";
lblMsg.Text += Environment.NewLine;
} // 通过 Confirmed 事件和 Closed 事件的结合,可以判断出用户是否点击了“取消”按钮或者按了“返回键”
private void PickerFlyout_Closed(object sender, object e)
{
lblMsg.Text += "closed";
lblMsg.Text += Environment.NewLine;
} // 非 xaml 方式弹出选取器控件
private async void button_Click_1(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
PickerFlyout flyout = new PickerFlyout();
flyout.Content = new TextBlock { Text="????????????????????????" };
bool result = await flyout.ShowAtAsync(button);
}
}
}

2、演示 ListPickerFlyout 的应用
ListPickerFlyoutDemo.xaml

<Page
x:Class="Demo.Control.ListPickerFlyoutDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Demo.Control"
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>
<StackPanel Orientation="Vertical"> <!--
弹出简单的列表选取器控件
Title - 弹出框的标题
DisplayMemberPath - 需要显示的绑定对象中的指定字段
SelectedValuePath - 调用 SelectedValue 时,返回的是选中对象中的指定字段的值
ItemsPicked - 用户选中某一 item 后触发的事件
-->
<Button Content="Show ListPicker(simple)">
<Button.Flyout>
<ListPickerFlyout x:Name="listPickerFlyoutSimple" Title="请选择"
DisplayMemberPath="Title" SelectedValuePath="Title"
ItemsPicked="listPickerFlyoutSimple_ItemsPicked" Closed="listPickerFlyout_Closed">
</ListPickerFlyout>
</Button.Flyout>
</Button> <!--
弹出单选列表选取器控件
Title - 弹出框的标题
SelectionMode - 选择模式(Single 或 Multiple)
ItemsPicked - 用户选中某一 item 后触发的事件
-->
<Button Content="Show ListPicker(single)" Margin="0 10 0 0">
<Button.Flyout>
<ListPickerFlyout x:Name="listPickerFlyoutSingle" Title="请选择"
SelectionMode="Single"
ItemsPicked="listPickerFlyoutSingle_ItemsPicked" Closed="listPickerFlyout_Closed">
<ListPickerFlyout.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ImageUrl}" Width="20" Height="20" />
<TextBlock Text="{Binding Title}" FontSize="20" Margin="10 0 0 0" />
</StackPanel>
</DataTemplate>
</ListPickerFlyout.ItemTemplate>
</ListPickerFlyout>
</Button.Flyout>
</Button> <!--
弹出多选列表选取器控件(有“完成”按钮和“取消”按钮)
Title - 弹出框的标题
SelectionMode - 选择模式(Single 或 Multiple)
ItemsPicked - 用户单击“完成”按钮后触发的事件
-->
<Button Content="Show ListPicker(multi)" Margin="0 10 0 0">
<Button.Flyout>
<ListPickerFlyout x:Name="listPickerFlyoutMulti" Title="请选择"
SelectionMode="Multiple"
ItemsPicked="listPickerFlyoutMulti_ItemsPicked" Closed="listPickerFlyout_Closed">
<ListPickerFlyout.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ImageUrl}" Width="20" Height="20" />
<TextBlock Text="{Binding Title}" FontSize="20" Margin="10 0 0 0" />
</StackPanel>
</DataTemplate>
</ListPickerFlyout.ItemTemplate>
</ListPickerFlyout>
</Button.Flyout>
</Button> <TextBlock Name="lblMsg" Margin="0 10 0 0" /> </StackPanel>
</Grid>
</Page>

ListPickerFlyoutDemo.xaml.cs

/*
* ListPickerFlyout - 列表选取器控件(wp only)
* ItemsSource - 数据源
*
* ShowAtAsync(FrameworkElement target) - 弹出列表选取器控件
* Hide() - 隐藏弹出框
*
* ItemsPicked - 用户选中列表中的项后触发的事件
* Opening, Opened, Closed - 几个顾名思义的事件
*/ using System;
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; namespace Demo.Control
{
public sealed partial class ListPickerFlyoutDemo : Page
{
private ObservableCollection<ItemModel> _items = new ObservableCollection<ItemModel>(); public ListPickerFlyoutDemo()
{
this.InitializeComponent();
} protected override void OnNavigatedTo(NavigationEventArgs e)
{
// 构造并绑定数据
for (int i = ; i < ; i++)
{
_items.Add(new ItemModel()
{
Title = (i.ToString()),
ImageUrl = "/Assets/Kid.png"
});
}
listPickerFlyoutSimple.ItemsSource = _items;
listPickerFlyoutSingle.ItemsSource = _items;
listPickerFlyoutMulti.ItemsSource = _items;
} // 用户选中某一 item 后触发的事件
private void listPickerFlyoutSimple_ItemsPicked(ListPickerFlyout sender, ItemsPickedEventArgs args)
{
lblMsg.Text += "selected value: " + sender.SelectedValue;
lblMsg.Text += Environment.NewLine;
} // 用户选中某一 item 后触发的事件
private void listPickerFlyoutSingle_ItemsPicked(ListPickerFlyout sender, ItemsPickedEventArgs args)
{
lblMsg.Text += "selected title: " + ((ItemModel)sender.SelectedItem).Title;
lblMsg.Text += Environment.NewLine;
} // 用户单击“完成”按钮后触发的事件
private void listPickerFlyoutMulti_ItemsPicked(ListPickerFlyout sender, ItemsPickedEventArgs args)
{
// 此次多选操作删除的 items
foreach (var item in args.RemovedItems)
{
lblMsg.Text += "removed item title: " + ((ItemModel)item).Title;
lblMsg.Text += Environment.NewLine;
} // 此次多选操作新增的 items
foreach (var item in args.AddedItems)
{
lblMsg.Text += "added item title: " + ((ItemModel)item).Title;
lblMsg.Text += Environment.NewLine;
}
} // 通过 ItemsPicked 事件和 Closed 事件的结合,可以判断出用户是否点击了“取消”按钮或者按了“返回键”
private void listPickerFlyout_Closed(object sender, object e)
{
lblMsg.Text += "closed";
lblMsg.Text += Environment.NewLine;
} class ItemModel
{
public string Title { get; set; }
public string ImageUrl { get; set; }
}
}
}

OK
[源码下载]

与众不同 windows phone (50) - 8.1 新增控件: PickerFlyout, ListPickerFlyout的更多相关文章

  1. 与众不同 windows phone (49) - 8.1 新增控件: 概述, ContentDialog, MapControl

    [源码下载] 与众不同 windows phone (49) - 8.1 新增控件: 概述, ContentDialog, MapControl 作者:webabcd 介绍与众不同 windows p ...

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

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

  3. 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom

    [源码下载] 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom 作者:webab ...

  4. Windows 8.1 应用再出发 - 几种新增控件(1)

    Windows 8.1 新增的一些控件,分别是:AppBar.CommandBar.DatePicker.TimePicker.Flyout.MenuFlyout.SettingsFlyout.Hub ...

  5. Windows 8.1 应用再出发 - 几种新增控件(2)

    本篇我们接着来介绍Windows 8.1 的新增控件,分别是:Flyout.MenuFlyout.SettingsFlyout.Hub 和 Hyperlink. 1. Flyout Flyout被称为 ...

  6. Windows 8.1 应用再出发 (WinJS) - 几种新增控件(2)

    上篇我们介绍了Windows 8.1 和 WinJS 中新增控件中的 AppBarCommand.BackButton.Hub.ItemContainer,本篇我们接着来介绍 NavBar.Repea ...

  7. 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar

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

  8. 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker

    [源码下载] 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker 作者:webabcd 介绍重新想象 Windows 8.1 ...

  9. 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout

    [源码下载] 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout 作者:webabcd 介绍重新想象 ...

随机推荐

  1. ARCGIS10.1 GeoDatabase深入理解:客户端连接与退出地理数据库时系统表的初始化

    平台软件:ARCIGS10.1 ,SQL Server2008R2 目的:了解客户端在连接arcgis 空间地理数据库后,地理数据库会做些什么样的初始化工作 准备工作: 1.准备好数据库日志文件查看工 ...

  2. RxJava基本流程和lift源码分析

    1.subscribe过程 2.lift过程

  3. 关于imp无法导出空表

    前天在业务库中导出完整库时,再导入到新库时发现部分表丢失. 看日志后分析是部分空表没有导出.查google知,11G中新特性,当表无数据时,不分配segment,以节省空间.而使用exp命令时,无Se ...

  4. AIDL示例

    背景 最近在考虑项目重构的时候,考虑将项目拆分成两个APK,一个用于数据服务,一个用于UI展示. 数据服务APK向自己编写APK提供数据,同时也可以向第三方提供数据.考虑使用这样的方式代替向第三方提供 ...

  5. Cubieboard2裸机开发之(四)定时器操作

    前言 在Cubieboard2裸机开发之(三)里用到了一个延时函数delay,它的延时时间是不精确的,因此为了能够精确延时,就需要定时器的配合.定时器可以精确延时的一个重要原因是它的计时时钟(或者说频 ...

  6. preg_match_all正则表达式的基本使用

    了解正则表达式之前,须要掌握一些常用的正则表达式的基础知识,这些如果能记得最好记得,记不住须要用的时候能查到就行,就多个特殊字符,所以说正则表达式玩的就是特殊,具体大家可以查看更加细致的说明. pre ...

  7. 尝鲜CodeBlocks

    在寻找跨平台的C++ IDE,就尝试了CodeBlocks,写了个HelloWorld,测试了一下C++11的代码,我很喜欢他的代码着色,看着很清爽. 记得要打开C++11的支持:

  8. 个性化EDM数据营销的三大提醒

    EDM数据营销行业已经进入个性化时代.但是怎样实现个性化仍然是一个重大课题.国内领先的智能化邮件营销服务商Focussend一直致力于探索和研究邮件营销领域的先进知识和做法,旨在为企业和个人提供更多有 ...

  9. NET实现微信分享和获取openid

    VS2010开发,MVC3架构. 通过调用微信官方接口实现获取openid,和分享好友功能,实现获取signature和jsapi_ticket,并在服务端进行缓存AccessToken和jsapi_ ...

  10. Android 开发框架汇总

    Android 开发框架汇总 时间过的真快,转眼间就要进入到16年的8月了,现在应该是三伏期间,一个字“热”.前端时间整理了一篇“JS前端框架汇总”,然后紧接着又抽时间学习了一下Android开发,在 ...