Control (Text Class): TextBox, PasswordBox

Source: Internet
Author: User
Tags touch

Introduced
Last Stand Windows 10 control (text Class)

    • Textbox
    • PasswordBox



Example
1. Example of a TextBox 1
Controls/textcontrol/textboxdemo1.xaml

<page x:class= "Windows10.Controls.TextControl.TextBoxDemo1" xmlns= "http://schemas.microsoft.com/winfx/2006/ Xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: Windows10.Controls.TextControl "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= "0" > <!--textbox-text input box text-text value Header-can set a plain text, cannot hit the test, empty header words will not occupy any space HeaderTemplate-can set the header to any Xam                    L, and support hit test MaxLength-Maximum number of characters (default is 0 means no limit) Placeholdertext-placeholder watermark Acceptsreturn-whether to allow input and display of the carriage return and line break isspellcheckenabled-whether to turn on spell checking function Istextpredictionen Abled-whether to turn on input prediction function DesiredcandidatewindoWalignment-ime Alignment (Ime-input method Editor; Sip-soft Input Panel) Default-When a hard keyboard is used, the IME moves with the cursor, and when a soft keyboard is used, the IME stops at the SIP Bo                        Ttomedge-When using a hard keyboard, the IME aligns with the bottom and left edges of the text edit control (only the Microsoft IME is tested, perhaps a third-party input method does not implement an interface), and when a soft keyboard is used, the IME stops at SIP-- <textbox name= "TextBox1" margin= "5" height= "header=" "text box" place                     holdertext= "Enter your text" maxlength= "textwrapping=" Wrap "                     Acceptsreturn= "true" isspellcheckenabled= "False" istextpredictionenabled= "true"                     desiredcandidatewindowalignment= "Default"/> <textbox name= "TextBox2" margin= "5"                text= "TextBox2" textalignment= "Center" isreadonly = "True" >               <TextBox.HeaderTemplate> <DataTemplate>         <textblock text= "text box" foreground= "Red"/> </DataTemplate> </text Box.headertemplate> </TextBox> <!--inputscope-Specify SIP (Soft Input Panel)                Type-<textbox name= "TextBox3" margin= "5" inputscope= "number"/> <!--             Set this TextBox on the codebehind end InputScope--<textbox name= "TextBox4" margin= "5"/> <!--textwrapping-line wrapping NoWrap-no wrap wrap-line wrap, truncate if necessary Word wrapwholewords-wraps, but never truncates a word, even if the word may be incomplete (tested invalid, TextBlock is supported)-<text            Box width= "horizontalalignment=" "left" text= "Abcdefghijklmnopq www" margin= "5" textwrapping= "NoWrap"/>            <textbox width= "horizontalalignment=" "left" text= "Abcdefghijklmnopq www" margin= "5" textwrapping= "Wrap"/>           <!--      TextAlignment-Horizontal alignment of text Center, left (default), right, Justify (justified, tested invalid, TextBlock supported) -<textbox text= "I am a &quot; textblock&quot; " margin= "5" textalignment= "right"/> </StackPanel> </Grid></Page>

Controls/textcontrol/textboxdemo1.xaml.cs

/* TextBox-Text input box (inherit from Control, see/controls/basecontrol/controldemo/) */using windows.ui.xaml;using windows.ui.xaml.controls;using windows.ui.xaml.input;namespace windows10.controls.textcontrol{Public    sealed Partial class Textboxdemo1:page    {public        TextBoxDemo1 ()        } {this            . InitializeComponent ();            This. Loaded + = textboxdemo1_loaded;        }        private void Textboxdemo1_loaded (object sender, RoutedEventArgs e)        {            //inputscope
   inputscope scope = new InputScope ();            Inputscopename name = new Inputscopename ();            Name. Namevalue = Inputscopenamevalue.chinesefullwidth;            Scope. Names.add (name);            Textbox4.inputscope = scope;        }}    }


2. Example of a TextBox 2
Controls/textcontrol/textboxdemo2.xaml

 <page x:class= "Windows10.Controls.TextControl.TextBoxDemo2" xmlns= "http://schemas.microsoft.com/winfx/ 2006/xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: Windows10.Controls.TextControl "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= "0" > <!--for displaying Segoe UI Emoji characters--<textbox Name= "Tex TBox1 "margin=" 5 "textwrapping=" Wrap "/> <textbox name=" TextBox2 "margin=" 5 "/> <textblo CK name= "TextBlock2" margin= "5"/> <textbox name= "TextBox3" margin= "5"/> <scrollviewer margin= "5" height= "> <textblock name=" TextBlock3 "/> </ScrollViewer> & Lt;/stackpanel> </grid></page> 

Controls/textcontrol/textboxdemo2.xaml.cs

/* TextBox-Text input box (inherit from Control, see/controls/basecontrol/controldemo/) * iscolorfontenabled-color display Segoe UI Em Characters such as Oji (the default is True) * SelectAll ()-Selects all (before you can do this with the focus) * Select (int start, int length)-Select the contents of the specified range (after the focus is taken, To do this) * SelectedText-Selected Content * SelectionStart-the starting position of the selection * SelectionLength-the number of characters of the selection * SELECTIONHIGHL Ightcolor-Color of selected text * Preventkeyboarddisplayonprogrammaticfocus-whether the soft keyboard is not displayed when the textbox gets focus by focusstate.programmatic * Getlinguisticalternativesasync ()-Gets a list of candidate words in the Input Method Editor (IME) window (tested only by Microsoft IME, perhaps a third-party IME does not implement an interface) * GETRECTFROMCHARACTE  Rindex (int charIndex, bool Trailingedge)-Gets the Rect object of the edge position of the specified character * CharIndex-the position of the character * Trailingedge-false Represents the front edge (left edge), true for the back edge (right edge) * * Description of related events for TextBox see the comments in the Code section */using system;using system.text;using windows.ui;using Wind oWS. Ui. Popups;using windows.ui.xaml;using windows.ui.xaml.controls;using Windows.ui.xaml.media;namespace windows10.controls.textcontrol{Public Sealed partial class Textboxdemo2:page {public TextBoxDemo2 () {this.            InitializeComponent (); This.        Loaded + = textboxdemo2_loaded;            private void Textboxdemo2_loaded (object sender, RoutedEventArgs e) {//display Segoe UI Emoji character            StringBuilder strcontect = new StringBuilder (); for (int code = 0x1f600; code < 0X1F6C6; code++) {strcontect.append (char).            CONVERTFROMUTF32 (code));            }//Whether characters such as Segoe UI Emoji are displayed in color (the default value is True) textbox1.iscolorfontenabled = true;            TextBox1.Text = Strcontect.tostring ();            TextBox2.Text = "123456"; Soft keyboard Textbox2.preventkeyboarddisplayonprogrammaticfocus = Tru is not displayed when TextBox2 is getting focus through focusstate.programmatic            E            By focusstate.programmatic let TextBox2 get Focus Textbox2.focus (focusstate.programmatic);          After the focus is taken, Select () or SelectAll ()  Textbox2.select (1, 4);            SelectAll ()-Check all Textbox2.selectionhighlightcolor = new SolidColorBrush (colors.orange);            Textblock2.text = "SelectedText:" + textbox2.selectedtext;            Textblock2.text + = Environment.NewLine;            Textblock2.text + = "SelectionStart:" + textbox2.selectionstart;            Textblock2.text + = Environment.NewLine;            Textblock2.text + = "SelectionLength:" + textbox2.selectionlength;            Textblock2.text + = Environment.NewLine; Gets the 1th character of the left edge of the Rect object Textblock2.text + = "Getrectfromcharacterindex (0, false):" + Textbox2.getrectfromchar Acterindex (0, false).            ToString ();            Textblock2.text + = Environment.NewLine; Gets the 1th character of the right edge of the Rect object Textblock2.text + = "Getrectfromcharacterindex (0, true):" + Textbox2.getrectfromchara Cterindex (0, True).                        ToString (); A description of the relevant event in the TextBox and a demonstration of the event triggered when the text changed textbox3.textchanging + =textbox3_textchanging;            Event triggered when text changes textbox3.textchanged + = textbox3_textchanged;            Event triggered after the selected text has changed textbox3.selectionchanged + = textbox3_selectionchanged;            Event triggered when pasting operation in TextBox textbox3.paste + = Textbox3_paste;            Event triggered when a context menu is opened in a TextBox (touch screen long press or right mouse button) textbox3.contextmenuopening + = textbox3_contextmenuopening; Events that are triggered when an Input Method Editor (IME) window is opened, updated, or closed (tested only by Microsoft IME, perhaps by a third-party input method that does not implement an interface) textbox3.candidatewindowboundschanged + = Text            box3_candidatewindowboundschanged;            Event triggered when text that consists of Input Method Editor (IME) changes textbox3.textcompositionchanged + = textbox3_textcompositionchanged;            The event that is triggered when a user starts composing text by entering a method Editor (IME) textbox3.textcompositionstarted + = textbox3_textcompositionstarted;        The event that is triggered when the user stops composing text through the Input Method Editor (IME) textbox3.textcompositionended + = textbox3_textcompositionended; } private void Textbox3_textchanging (TExtbox sender, Textboxtextchangingeventargs args) {textblock3.text + = "textchanging:" + textbox3.text;        Textblock3.text + = Environment.NewLine; private void Textbox3_textchanged (object sender, Textchangedeventargs e) {textblock3.text + = "            TextChanged: "+ textbox3.text;        Textblock3.text + = Environment.NewLine; private void Textbox3_selectionchanged (object sender, RoutedEventArgs e) {textblock3.text + = "            SelectionChanged: "+ textbox3.selectedtext;        Textblock3.text + = Environment.NewLine; Private async void Textbox3_paste (object sender, Textcontrolpasteeventargs e) {await new Messa Gedialog ("Paste disabled").            Showasync ();        Set the routed event to handled, thereby disabling the paste function e.handled = true; private void Textbox3_contextmenuopening (object sender, Contextmenueventargs e) {Textblock3.te          XT + = "contextmenuopening";  Textblock3.text + = Environment.NewLine;        private void Textbox3_candidatewindowboundschanged (TextBox sender, Candidatewindowboundschangedeventargs args) {//Candidatewindowboundschangedeventargs.bounds-Gets the Rect object of the IME window Textblock3.text + = "Cand Idatewindowboundschanged: "+ args.            Bounds.tostring ();        Textblock3.text + = Environment.NewLine;             } private async void textbox3_textcompositionchanged (TextBox sender, Textcompositionchangedeventargs args) { Textcompositionchangedeventargs.startindex-The starting position of text that is composed of IMEs//Textcompositionchangedeventarg S.length-The length of the text that is composed of the IME Textblock3.text + = $ "textcompositionchanged Startindex:{args. StartIndex}, Length:{args.            Length} ";            Textblock3.text + = Environment.NewLine; Getlinguisticalternativesasync ()-Gets a list of candidate words in the Input Method Editor (IME) window (tested only by Microsoft IME, perhaps a third-party input method does not implement an interface) Var Candidateword s = await textbox3.getlinguisticAlternativesasync (); Textblock3.text + = "Candidate Words:" + string.            Join (",", candidatewords);;        Textblock3.text + = Environment.NewLine;            } private void textbox3_textcompositionstarted (TextBox sender, Textcompositionstartedeventargs args) { Textcompositionstartedeventargs.startindex-The starting position of text that is composed of IMEs//Textcompositionstartedeventargs.leng Th-the length of the text that is composed of IMEs Textblock3.text + = $ "textcompositionstarted Startindex:{args. StartIndex}, Length:{args.            Length} ";        Textblock3.text + = Environment.NewLine;            } private void textbox3_textcompositionended (TextBox sender, Textcompositionendedeventargs args) { Textcompositionendedeventargs.startindex-The starting position of text that is composed of IMEs//Textcompositionendedeventargs.length-by The IME consists of the length of the text Textblock3.text + = $ "textcompositionended Startindex:{args. StartIndex}, Length:{args.            Length} "; Textblock3.text + = EnvironmeNt.        NewLine; }    }}


3. Examples of PasswordBox
Controls/textcontrol/passwordboxdemo.xaml

<page x:class= "Windows10.Controls.TextControl.PasswordBoxDemo" xmlns= "http://schemas.microsoft.com/winfx/2006 /xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: Windows10.Controls.TextControl "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= "0" > <!--PasswordBox-Password entry box Password-Password Value passwordchar-the password substitution character shown in the Password box. The default value is "ispasswordrevealbuttonenabled-Displays the show password clear text button (deprecated) Passwordrevealmode-password display                        Show mode Peek-ciphertext display, press the "Show password Clear text" button when the clear text (default) Hidden-ciphertext display, "Show password Clear text" button is not visible Visible-Clear text, "Show password Clear text" button is not visible Header-can be set to a plaintext, cannot hit the test, empty Header words will not occupy any space                    HeaderTemplate-You can set the Header to any XAML and support hit test MaxLength-Maximum number of characters (default is 0 means no limit) Placeholdertext-Placeholder Watermark--<passwordbox name= "PasswordBox1" width= " "Margin=" 5 "horizontalalignment=" left "header=" password "placeholdertext=" E                         Nter your password "maxlength=" 6 "passwordchar=" @ " Passwordrevealmode= "Peek"/> <passwordbox name= "PasswordBox2" width= "$" margin= "5" horizontalalignmen                        T= "Left" > <PasswordBox.HeaderTemplate> <DataTemplate> <textblock text= "Password" foreground= "Red"/> </DataTemplate> </passwordbo x.headertemplate> </PasswordBox> <textblock name= "TextBlock" margin= "5"/> &lt ;/stackpanel> </grid></page> 

Controls/textcontrol/passwordboxdemo.xaml.cs

/* * PasswordBox-Password input box (inherit from Control, see/controls/basecontrol/controldemo/) * Password-Password value * SelectAll ()-Check All characters in PasswordBox (before you can do this with the focus) * Selectionhighlightcolor-Color of selected text * PREVENTKEYBOARDDISPLAYONPROGRAMMATICFOCU  S-event that triggers when the soft keyboard * Passwordchanged-password property value changes when the PasswordBox gets focus by focusstate.programmatic * Paste-in Event triggered during paste operation in PasswordBox * contextmenuopening-event triggered when a context menu is opened in PasswordBox (touch screen long press or right mouse button) */using system;using Windows . Ui;using windows.ui.popups;using windows.ui.xaml;using windows.ui.xaml.controls;using Windows.UI.Xaml.Media; namespace windows10.controls.textcontrol{public sealed partial class Passwordboxdemo:page {public passwor Dboxdemo () {this.            InitializeComponent (); This.        Loaded + = passwordboxdemo_loaded;  private void Passwordboxdemo_loaded (object sender, RoutedEventArgs e) {Passwordbox2.password =            "123456"; When through Focusstate.proGrammatic the soft keyboard Passwordbox2.preventkeyboarddisplayonprogrammaticfocus = True when you let PasswordBox2 get focus;            By focusstate.programmatic let PasswordBox2 get Focus Passwordbox2.focus (focusstate.programmatic); Passwordbox2.selectall ();            You need to get the focus before you can do this passwordbox2.selectionhighlightcolor = new SolidColorBrush (colors.orange);            Passwordbox2.passwordchanged + = (x, y) = = {Textblock.text = Passwordbox2.password;            }; Passwordbox2.paste + = Async (x, y) = {await new Messagedialog ("Paste disabled").                Showasync ();            Set the routed event to handled, thereby disabling the paste function y.handled = true;            };        Passwordbox2.contextmenuopening + = (x, y) + = {//Trigger Condition: Touch screen long press or right mouse button}; }    }}

Control (Text Class): TextBox, PasswordBox

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.