[源码下载]

与众不同 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. C#后台弹出对话框

    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='jav ...

  2. DRUPAL 慢的原因

    不止一次听人抱怨DRUPAL 慢,在本地开发环境尤为常见,较为常见的原因有:- 本地环境造成慢的原因,最常见的是由update manager  造成的,如果你发现你开的DRUPAL 页面 一直在等待 ...

  3. Kafka 分区备份实战

    1.概述 在 Kafka 集群中,我们可以对每个 Topic 进行一个或是多个分区,并为该 Topic 指定备份数.这部分元数据信息都是存放在 Zookeeper 上,我们可以使用 zkCli 客户端 ...

  4. mac下python实现vmstat

    mac下没有linux/unix 的vmstat,只有vm_stat; sh-3.2# vm_statMach Virtual Memory Statistics: (page size of 409 ...

  5. Spring进阶教程之在ApplicationContext初始化完成后重定义Bean

    前言 很久没有写博客了,也是两个原因:一是自己觉得一直在班门弄斧,其实自己没什么技术可言:二是很多朋友的问题实际上可以自行解决,我经常觉得不该我来过问,或者是有时候我认为技术还得靠自己钻研,我一两句话 ...

  6. WinForm 批量设置指定控件中的控件状态

    在开发中常遇到当点击某个按钮的时候,禁用文本框或按钮的的状态,以防止误操作,下面的代码是我已批量设置指定控件中的按钮状态的代码,同理可以延伸出很多操作. /// <summary> /// ...

  7. android自定义TabView实现圆角列表

    看到很多应用的设置界面都有圆角效果的列表,类似下面的 下面说说我的实现原理:继承LinearLayout,然后设置一个自定义的TabAdapter,类似于listview,添加一个setAdapter ...

  8. SQLServer创建维护计划失败 错误c001f011

    重新注册dts.dll文件,在运行里输入命令:(x64)regsvr32 "C:\Program Files\Microsoft SQL Server\100\DTS\Binn\dts.dl ...

  9. python 教程_【python 基础教程详解】

    Lesson 1 准备好学习Python的环境下载的地址是:www.python.org为了大家的方便,我在校内作了copy:http://10.1.204.2/tool/compiler&I ...

  10. Linux系统下安装rz/sz命令及使用说明

    对于经常使用Linux系统的人员来说,少不了将本地的文件上传到服务器或者从服务器上下载文件到本地,rz / sz命令很方便的帮我们实现了这个功能,但是很多Linux系统初始并没有这两个命令.今天,我们 ...