与众不同 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的更多相关文章
- 与众不同 windows phone (49) - 8.1 新增控件: 概述, ContentDialog, MapControl
[源码下载] 与众不同 windows phone (49) - 8.1 新增控件: 概述, ContentDialog, MapControl 作者:webabcd 介绍与众不同 windows p ...
- 与众不同 windows phone (51) - 8.1 新增控件: DatePickerFlyout, TimePickerFlyout
[源码下载] 与众不同 windows phone (51) - 8.1 新增控件: DatePickerFlyout, TimePickerFlyout 作者:webabcd 介绍与众不同 wind ...
- 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom
[源码下载] 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom 作者:webab ...
- Windows 8.1 应用再出发 - 几种新增控件(1)
Windows 8.1 新增的一些控件,分别是:AppBar.CommandBar.DatePicker.TimePicker.Flyout.MenuFlyout.SettingsFlyout.Hub ...
- Windows 8.1 应用再出发 - 几种新增控件(2)
本篇我们接着来介绍Windows 8.1 的新增控件,分别是:Flyout.MenuFlyout.SettingsFlyout.Hub 和 Hyperlink. 1. Flyout Flyout被称为 ...
- Windows 8.1 应用再出发 (WinJS) - 几种新增控件(2)
上篇我们介绍了Windows 8.1 和 WinJS 中新增控件中的 AppBarCommand.BackButton.Hub.ItemContainer,本篇我们接着来介绍 NavBar.Repea ...
- 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar
[源码下载] 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...
- 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker
[源码下载] 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker 作者:webabcd 介绍重新想象 Windows 8.1 ...
- 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout
[源码下载] 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout 作者:webabcd 介绍重新想象 ...
随机推荐
- JavaScript 事件——“事件类型”中“复合事件”和“变动事件”的注意要点(转)
复合事件 复合事件是DOM3级事件中心添加的一类事件,用于处理IME的输入序列. compositionstart.compositionupdate.compositionend 复合事件有以下三中 ...
- iOS 自定义滑动切换TabBar
貌似经常会用到,自己整理收藏起来,方便日后查找备用. 效果如图: 由于制作gif,调整了属性,所以看起来的效果不好.如果用默认配置,生成的gif会很大. 制作gif: 1.使用QuickTimePla ...
- SQLSERVER吞噬内存解决记录
现在手上有一个不大不小的系统,运行了一段时间,因为是24*7不断运行,所以内存逐渐增高,慢慢的会飙到95%以上,然后不得不重启电脑,因为用的是云,怕虚拟机重启down掉起不来,重启操作还只能在凌晨4. ...
- awstats 日志分析工具linux下的安装和使用
合并日志文件可以使用 bash 的sort命令: -o log_all access*.log 也可以使用 awstats 提供的 logresolvemerge.pl -showsteps acc ...
- JQuery 表格拖动调整列宽效果
类似于桌面程序中的表格拖动表头的效果,当鼠标停留在表头边框线上时,鼠标会变成表示左右拖动的形状,接着拖动鼠标,会在表格中出现一条随鼠标移动的竖线,最后放开鼠标,表格列宽会被调整.最近比较空闲,便自己动 ...
- tolua++实现分析
项目正在使用cocos2dx的lua绑定,绑定的方式是tolua++.对大规模使用lua代码信心不是很足,花了一些时间阅读tolua++的代码,希望对绑定实现的了解,有助于项目对lua代码的把控.从阅 ...
- 一步步教你搭建VS环境下用C#写WebDriver脚本
一步步教你搭建VS环境下用C#写WebDriver脚本http://www.automationqa.com/forum.php?mod=viewthread&tid=3529&fro ...
- sublime3+wamp配置php,(无需配环境变量)
思来想去,最后还是决定给自己的手游加简单后端验证.好久没搞php了,最近搜了搜资料,发现现在php比几年前方便简单的多,有wampserver和sublime用.想想当年我还用记事本+phnow呢. ...
- sizeof and strlen整理
sizeof 定义 计算对象或类型所占用的字节数(byte) 记住是字节数,而不是个数 语法 sizeof(对象) int i; sizeof(i); sizeof(类型) sizeof(int); ...
- protobuf-net
protobuf是google的一个开源项目,可用于以下两种用途: (1)数据的存储(序列化和反序列化),类似于xml.json等: (2)制作网络通信协议. 源代码下载地址:https://gith ...