背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox
2021-05-12 22:26
标签:sync http model tran ble comm blend art load [源码下载] 作者:webabcd 示例 Controls/SelectionControl/SelectorDemo.xaml.cs Controls/SelectionControl/ComboBoxDemo.xaml.cs OK 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox 标签:sync http model tran ble comm blend art load 原文地址:http://www.cnblogs.com/lonelyxmas/p/7567294.html
介绍
背水一战 Windows 10 之 控件(选择类)
1、Selector(基类) 的示例
Controls/SelectionControl/SelectorDemo.xamlPage
x:Class="Windows10.Controls.SelectionControl.SelectorDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.SelectionControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:common="using:Windows10.Common">
Grid Background="Transparent">
StackPanel Margin="10 0 10 10">
TextBlock Name="textBlock" Margin="5" />
ComboBox Name="comboBox1" Margin="5 20 5 5" ItemsSource="{x:Bind Employees}" Width="200" HorizontalAlignment="Left">
ComboBox.ItemTemplate>
DataTemplate x:DataType="common:Employee">
StackPanel Orientation="Horizontal">
TextBlock Text="{x:Bind Name}" />
TextBlock Text="{x:Bind Age}" Margin="5 0 0 0" />
StackPanel>
DataTemplate>
ComboBox.ItemTemplate>
ComboBox>
TextBlock Name="lblMsg1" Margin="5" />
ComboBox Name="comboBox2" Margin="5 20 5 5" ItemsSource="{x:Bind Employees}" Width="200" HorizontalAlignment="Left">
ComboBox.ItemTemplate>
DataTemplate x:DataType="common:Employee">
StackPanel Orientation="Horizontal">
TextBlock Text="{x:Bind Name}" />
TextBlock Text="{x:Bind Age}" Margin="5 0 0 0" />
StackPanel>
DataTemplate>
ComboBox.ItemTemplate>
ComboBox>
TextBlock Name="lblMsg2" Margin="5" />
ComboBox x:Name="comboBox3" Margin="5 20 5 5" Width="200" HorizontalAlignment="Left">
ComboBoxItem Content="ComboBoxItem1" IsSelected="True" />
ComboBoxItem Content="ComboBoxItem2" />
ComboBoxItem Content="ComboBoxItem3" />
ComboBox>
StackPanel>
Grid>
Page>
/*
* Selector(基类) - 选择器控件基类(继承自 ItemsControl, 请参见 /Controls/CollectionControl/ItemsControlDemo/)
* SelectedIndex - 选中项的索引
* SelectedItem - 选中项的数据对象
* SelectedValuePath - 选中项的值的字段路径,默认值为空字符串(此时 SelectedValue 的结果与 SelectedItem 相同)
* SelectedValue - 选中项的值(字段路径通过 SelectedValuePath 设置)
* bool GetIsSelectionActive(DependencyObject element) - 用于获取指定的 Selector 控件是否是焦点状态
* 如果是焦点状态,则按下键盘 enter 键会弹出此 Selector 控件的选项列表,按下 esc 键会隐藏此 Selector 控件的选项列表
* IsSynchronizedWithCurrentItem - 暂时认为没用吧,因为设置为 true 后,在 runtime 会报错
* SelectionChanged - 选中项发生变化时触发的事件
*
*
* SelectorItem(基类) - Selector 的 Item(继承自 ContentControl, 请参见 /Controls/BaseControl/ContentControlDemo/)
* IsSelected - 是否被选中
*/
using System;
using System.Collections.ObjectModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows10.Common;
namespace Windows10.Controls.SelectionControl
{
public sealed partial class SelectorDemo : Page
{
public ObservableCollection
2、ComboBox 的示例
Controls/SelectionControl/ComboBoxDemo.xamlPage
x:Class="Windows10.Controls.SelectionControl.ComboBoxDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.SelectionControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:common="using:Windows10.Common">
Grid Background="Transparent">
StackPanel Margin="10 0 10 10">
ComboBox x:Name="comboBox1" Margin="5" Width="200" HorizontalAlignment="Left"
Header="comboBox1" PlaceholderText="PlaceholderText">
ComboBoxItem Content="ComboBoxItem1" />
ComboBoxItem Content="ComboBoxItem2" />
ComboBoxItem Content="ComboBoxItem3" />
ComboBox>
TextBlock Name="lblMsg1" Margin="5" />
ComboBox x:Name="comboBox2" ItemsSource="{x:Bind Employees}" Margin="5 20 5 5" Width="200" HorizontalAlignment="Left">
ComboBox.HeaderTemplate>
DataTemplate>
TextBlock Text="comboBox2" Foreground="Red" />
DataTemplate>
ComboBox.HeaderTemplate>
ComboBox.ItemTemplate>
DataTemplate x:DataType="common:Employee">
StackPanel Orientation="Horizontal">
TextBlock Text="{x:Bind Name}" />
TextBlock Text="{x:Bind Age}" Margin="5 0 0 0" />
StackPanel>
DataTemplate>
ComboBox.ItemTemplate>
ComboBox>
ComboBox Name="comboBox3" SelectedIndex="0" Width="200" HorizontalAlignment="Left" Margin="5 60 5 5">
x:String>Redx:String>
x:String>Greenx:String>
x:String>Bluex:String>
ComboBox>
StackPanel>
Grid>
Page>
/*
* ComboBox - 下拉框控件(继承自 Selector, 请参见 /Controls/SelectionControl/SelectorDemo.xaml)
* DropDownOpened - 下拉框打开(弹出选项列表)时触发的事件
* DropDownClosed - 下拉框关闭(隐藏选项列表)时触发的事件
* IsDropDownOpen - 下拉框是否处于打开状态
* MaxDropDownHeight - 下拉框打开后,其选项列表的最大高度
* SelectionBoxItem - 下拉框关闭后显示的数据对象(即下拉框的选项列表隐藏后,在下拉框中显示的数据对象
*
*
* ComboBoxItem - 下拉框控件的 item(继承自 SelectorItem, 请参见 /Controls/SelectionControl/SelectorDemo.xaml)
*/
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Controls;
using Windows10.Common;
namespace Windows10.Controls.SelectionControl
{
public sealed partial class ComboBoxDemo : Page
{
public ObservableCollection
[源码下载]
上一篇:背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch
下一篇:背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout
文章标题:背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox
文章链接:http://soscw.com/essay/84872.html