[源码下载]

与众不同 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. 解决Win7旗舰版开机后无线网络识别非常慢的问题

    最近电脑开机后WIFI识别和连接非常慢,不知何故.查看百度安全卫士的优化记录,发现其禁用了 Network List Service,将该服务设为自动启动,重启服务后,问题解决.PS:如此优化太可恶!

  2. SQL Server 几种锁的区别

    NOLOCK(不加锁)    此选项被选中时,SQL  Server  在读取或修改数据时不加任何锁.  在这种情况下,用户有可能读取到未完成事务(Uncommited  Transaction)或回 ...

  3. config中自定义配置

    1. 定义自己的KeyValue <section name="TestKeyValue" type="System.Configuration.NameValue ...

  4. jdbc无法连接数据解析

    1.网络原因 2.账户权限问题 账户是否赋予以下的权限: grant connect, resource to ADM_BI; grant read, write on directory BACKU ...

  5. Spring源码追踪3——AOP机制

    研究代码: spring配置文件 <cache:annotation-driven /> Java代码 @Cacheable(value = "test", key = ...

  6. Spark源码系列(五)分布式缓存

    这一章想讲一下Spark的缓存是如何实现的.这个persist方法是在RDD里面的,所以我们直接打开RDD这个类. def persist(newLevel: StorageLevel): this. ...

  7. Javascript类继承-机制-代码Demo【原创】

    最近看到<Javascript设计模式>,对js模拟的”继承方式“有了更深一步的了解,虽然之前也总是用到prototype.new ,但只是知其然不知所以然,现在将类继承的方法整理如下,暂 ...

  8. 自己做的加速app测试流程的小工具,目前打算开放使用,想注册的朋友抓紧了,嘻嘻

    为了加速小团队app的测试流程做了这个东西,www.xunce.net 主要特性: web: 一键上传app,方便随时下载 备注测试要点 添加附件,如checklist等文档  自动识别app版本,名 ...

  9. 【Xamarin报错】AndroidManifest.xml : warning XA0101: @(Content) build action is not supported

    部署xamarin.forms android时报错: Android\Properties\AndroidManifest.xml : warning XA0101: @(Content) buil ...

  10. apache2.4 以上设定gzip压缩

    国内很多文章都是抄来抄去,用不成,用我这个就可以了 编辑 http.conf 文件 去掉 #LoadModule headers_module modules/mod_headers.so 前面的注释 ...