World War I Windows 10 (32) and World War I 32

Source: Internet
Author: User

World War I Windows 10 (32) and World War I 32

[Download source code]


Backwater world war I Windows 10 (32)-control (selection class): Selector, ComboBox



Author: webabcd


Introduction
Controls for backwater world war I Windows 10 (selection class)

  • Selector
  • ComboBox



Example
1. Example of Selector (base class)
Controls/SelectionControl/SelectorDemo. xaml

<Page 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-drop-down box control, inherited from Selector. The following describes the knowledge points of Selector --> <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> </C OmboBox. 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"/> <! -- The item of the ComboBoxItem-drop-down box control is inherited from SelectorItem. The following describes the knowledge point of SelectorItem: IsSelected-selected or not --> <ComboBox x: name = "combox3" Margin = "5 20 5" Width = "200" HorizontalAlignment = "Left"> <ComboBoxItem Content = "ComboBoxItem1" IsSelected = "True"/> <ComboBoxItem content = "ComboBoxItem2"/> <ComboBoxItem Content = "ComboBoxItem3"/> </ComboBox> </StackPanel> </Grid> </Page>

Controls/SelectionControl/SelectorDemo. xaml. cs

/** Selector (base class)-Selector control base class (inherited from ItemsControl, see/Controls/CollectionControl/ItemsControlDemo /) * SelectedIndex-index of the selected item * SelectedItem-Data Object of the selected item * SelectedValuePath-path of the field of the value of the selected item. The default value is an empty string (in this case, the result of SelectedValue is the same as that of selected) * SelectedValue-value of the selected item (the Field path is set through SelectedValuePath) * bool GetIsSelectionActive (DependencyObject element)-used to obtain whether the specified Selector control is in focus state * if it is in focus state, press enter to display the options list of this Selector control. Press esc to hide the options list of this Selector control * IsSynchronizedWithCurrentItem-it is useless for the moment, because after it is set to true, windows will be thrown at runtime. UI. xaml. markup. xamlParseException * SelectionChanged-event triggered when the selected Item changes ** SelectorItem (base class)-Selector Item (inherited from ContentControl, see/Controls/BaseControl/ContentControlDemo /) * IsSelected-whether to select */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 <Employee> Employees {get; set ;}= TestData. getEmployees (30); public SelectorDemo () {this. initializeComponent (); this. loaded + = SelectorDemo_Loaded; // If SelectedValuePath is not set, the result of SelectedValue is the same as that of SelectedItem; // specify the field path of SelectedValue; comboBox2.SelectionChanged + = identifier;} private void identifier (object sender, RoutedEventArgs e) {DispatcherTimer dTimer = new DispatcherTimer (); dTimer. interval = TimeSpan. zero; dTimer. tick + = DTimer_Tick; dTimer. start ();} private void DTimer_Tick (object sender, object e) {textBlock. text = $"combox1 focus: {ComboBox. getIsSelectionActive (combox1)}, comboBox2 focus: {ComboBox. getIsSelectionActive (combox2)} ";} private void ComboBox1_SelectionChanged (object sender, SelectionChangedEventArgs e) {// e. removedItems-in this event, the selected items are canceled. // e. addedItems-in this event, the newly selected int selectedIndex = comboBox1.SelectedIndex; // SelectedItem is the selected Employee object // SelectedValue is the selected Employee object lblMsg1.Text = $"combox1 SelectedItem: {comboBox1.SelectedItem}, SelectedValue: {region} ";} private void ComboBox2_SelectionChanged (object sender, SelectionChangedEventArgs e) {int selectedIndex = comboBox2.SelectedIndex; // SelectedItem is the selected Employee object // SelectedValue is the value of the Name attribute of the selected Employee object lblMsg2.Text = $"comboBox2 SelectedItem: {comboBox2.SelectedItem}, SelectedValue: {comboBox2.SelectedValue }";}}}


2. Example of ComboBox
Controls/SelectionControl/ComboBoxDemo. xaml

<Page 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-drop-down box control Header-you can set a plain text item and cannot hit the test. If the Header is empty, it does not occupy any space. HeaderTemplate-you can set the Header to any xaml, and supports the hit test PlaceholderText-placeholder watermark --> <! -- Add data to ComboBox in xaml mode --> <ComboBox x: name = "combox1" Margin = "5" Width = "200" HorizontalAlignment = "Left" Header = "combox1" PlaceholderText = "PlaceholderText"> <ComboBoxItem Content = "ComboBoxItem1"/> <ComboBoxItem Content = "ComboBoxItem2"/> <ComboBoxItem Content = "ComboBoxItem3"/> </ComboBox> <TextBlock Name = "lblMsg1" Margin = "5"/> <! -- Bind data to ComboBox --> <ComboBox x: Name = "combox2" 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: Bi Nd Name} "/> <TextBlock Text =" {x: Bind Age} "Margin =" 5 0 0 0 "/> </StackPanel> </DataTemplate> </ComboBox. itemTemplate> </ComboBox> <! -- Add data to ComboBox in xaml mode (using strings directly ), in code-behind, you can use SelectedValue to directly obtain the selected string --> <ComboBox Name = "comboBox3" SelectedIndex = "0" Width = "200" HorizontalAlignment = "Left" Margin =" 5 60 5 5 "> <x: string> Red </x: String> <x: String> Green </x: String> <x: String> Blue </x: string> </ComboBox> </StackPanel> </Grid> </Page>

Controls/SelectionControl/ComboBoxDemo. xaml. cs

/** ComboBox-drop-down box control (inherited from Selector, see/Controls/SelectionControl/SelectorDemo. xaml) * events triggered when the DropDownOpened-drop-down box is opened (the Option List is displayed) * DropDownClosed-close the drop-down box (hide the Option List) * IsDropDownOpen-whether the drop-down box is open * MaxDropDownHeight-after the drop-down box is opened, the maximum height of the Option List * The data object displayed after the SelectionBoxItem-drop-down box is closed (that is, after the Option List in the drop-down box is hidden, the Data Object ** ComboBoxItem-the item of the drop-down box control displayed in the drop-down box (inherited from SelectorItem, see/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 <Employee> Employees {get; set ;}= TestData. getEmployees (30); public ComboBoxDemo () {this. initializeComponent (); Response + = response; Response + = comboboxappsdropdownclosed; comboBox2.MaxDropDownHeight = 40; comboBox2.Loaded + = (x, y) =>{// Note: To set the IsDropDownOpen attribute, wait until the ComboBox is loaded and set upload = true ;}}private void upload (object sender, object e) {lblMsg1.Text = "combox1 DropDownOpened";} private void comboboxincludropdownclosed (object sender, object e) {// you can obtain the ComboBox Option List through SelectionBoxItem to hide the Data object lblMsg1.Text = $"combox1 DropDownClosed, SelectionBoxItem: {comboBox1.SelectionBoxItem }";}}}



OK
[Download source code]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.