Welcome

首页 / 软件开发 / .NET编程技术 / Windows 8 Store Apps学习(5) 集合控件

Windows 8 Store Apps学习(5) 集合控件2013-12-04 博客园 王磊ComboBox, ListBox, FlipView, ItemsContr

介绍

重新想象 Windows 8 Store Apps 之集合控件

ComboBox - 下拉框

ListBox - 列表框

FlipView - 滑动视图控件

ItemsControl ItemsPresenter - ItemsPresenter 用来呈现 ItemsControl 的 Items

示例

1、ComboBox 的 Demo

ComboBoxDemo.xaml

<Pagex:Class="XamlDemo.Controls.ComboBoxDemo"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using:XamlDemo.Controls"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"><Grid Background="Transparent"> <StackPanel Margin="120 0 0 0"><!--ComboBox - 下拉框--> <!--xaml 方式为 ComboBox 添加数据--><ComboBox x:Name="comboBox" Width="200" Margin="5" HorizontalAlignment="Left"> <ComboBoxItem Content="ComboBoxItem1" /> <ComboBoxItem Content="ComboBoxItem2" /> <ComboBoxItem Content="ComboBoxItem3" /> </ComboBox><!-- 后台绑定方式为 ComboBox 添加数据 DisplayMemberPath - 指定数据源中需要被显示出来的字段名称 MaxDropDownHeight - 用于指定打开后的下拉框的最大高度 --><ComboBox x:Name="comboBoxWithBinding" DisplayMemberPath="Name" MaxDropDownHeight="100" Width="200" Margin="5" HorizontalAlignment="Left" /><!--通过模板设置 ComboBox 的每一项的布局和数据--><ComboBox ItemsSource="{Binding ItemsSource, ElementName=comboBoxWithBinding}" MaxDropDownHeight="100" Width="200" Margin="5" HorizontalAlignment="Left"> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Name}" /> <TextBlock Text="{Binding Age}" Margin="5 0 0 0" /> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox></StackPanel> </Grid> </Page>