当前位置: 首页>>代码示例>>C#>>正文


C# TextBox.Select方法代码示例

本文整理汇总了C#中System.Windows.Controls.TextBox.Select方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.Select方法的具体用法?C# TextBox.Select怎么用?C# TextBox.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.TextBox的用法示例。


在下文中一共展示了TextBox.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: doMask

 public static void doMask(bool textBoxChanged,TextBox textb)
 {
     if (textBoxChanged)
     {
         if (textb.Text.Trim().Length == 0) return;
         String s = getStringFromMasked(textb.Text);
         String res = doMaskOnce(s);
         if (res != "" && textb.Text!=res)
         {
             textb.Text = res;
             textb.Select(textb.Text.Length, 0);
         }
         textBoxChanged = false;
     }
 }
开发者ID:omid55,项目名称:real_state_manager,代码行数:15,代码来源:MyPriceTextBox.cs

示例2: BeginEditTextOnSelected

        internal void BeginEditTextOnSelected()
        {
            ItemLostFocus();

            selectedForEditing = (SelectedItem as ExplorerTreeViewItem);

            if (selectedForEditing == null) return;

            TextBox tb = new TextBox();
            tb.Text = selectedForEditing.Text;
            tb.LostFocus += tb_LostFocus;
            tb.KeyDown += tb_KeyDown;
            tb.Focusable = true;

            beforeEditingPath = selectedForEditing.FullPath;
            (selectedForEditing.Header as StackPanel).Children.RemoveAt(1);
            (selectedForEditing.Header as StackPanel).Children.Add(tb);
            selectedForEditing.CanDrag = false;

            tb.Select(0, tb.Text.Length - (System.IO.Path.GetExtension(tb.Text).Length));
            tb.Focus();
        }
开发者ID:Whitebeard86,项目名称:Gibbo2D,代码行数:22,代码来源:ProjectExplorerTreeView.xaml.cs

示例3: SubscribeTextChanged

        /// <summary>
        /// TextBoxの内容が変化したときの処理
        /// </summary>
        /// <param name="textBox"></param>
        public void SubscribeTextChanged(TextBox textBox)
        {

            var textChanged =
                Observable.FromEvent<TextChangedEventHandler, TextChangedEventArgs>
                (h => (sender, e) => h(e),
                h => textBox.TextChanged += h,
                h => textBox.TextChanged -= h);

            //カーソルを末尾に移動させる
            this.TextHistoryIndex
                .Buffer(textChanged.Where(y => textBox.Text.Length > 0))
                .Where(y => y.Count > 0)
                .Subscribe(y => textBox.Select(textBox.Text.Length, 0))
                .AddTo(this.Disposables);

            textChanged
                .Where(x => this.TextHistory.ContainsIndex(this.TextHistoryIndex.Value)
                    && textBox.Text != this.TextHistory[this.TextHistoryIndex.Value])
                .Subscribe(x =>
                {
                    this.InputText = textBox.Text;
                    this.textEdited = true;
                    //this.TextHistoryIndex.Value = this.TextHistory.Count;
                })
                .AddTo(this.Disposables);

        }
开发者ID:Boredbone,项目名称:Terminal,代码行数:32,代码来源:MainWindowViewModel.cs

示例4: TabItem_GotFocus

        private void TabItem_GotFocus(object sender, RoutedEventArgs e)
        {
            MainWindow wnd = new MainWindow();
            wnd.WndName = "Wnd_#";
            Wins.Add(new WindowSource(wnd));
            TCWndLines.Items.Insert(TCWndLines.Items.Count - 1,Wins.Last().TIWindow);
            TCWndLines.SelectedIndex = TCWndLines.Items.Count - 2;
            //TreeView TempTV = (((TCWndLines.Items[TCWndLines.Items.Count - 2] as TabItem).Content as ScrollViewer).Content as Grid).Children[0] as TreeView;
            Wins.Last().TVWindow.PreviewMouseLeftButtonDown +=TreeView_PreviewMouseLeftButtonDown;
            //WndTreeViews.Add(TempTV);

            int index = TCWndLines.SelectedIndex;
            TabItem CurrentTab = TCWndLines.Items[index] as TabItem;
            TextBox TBRename = new TextBox();
            TBRename.Tag = CurrentTab;
            TBRename.KeyDown += TBRename_KeyDown;
            TBRename.LostFocus += TBRename_LostFocus;
            TBRename.Text = Wins[index].Name;
            CurrentTab.Header = TBRename;
            TBRename.Select(0, TBRename.Text.Length);
            // тут необходимо передать фокус созданному TextBox
        }
开发者ID:okunokao,项目名称:GEoS,代码行数:22,代码来源:FormSourceItemsCache.xaml.cs

示例5: MITabRename_Click

 private void MITabRename_Click(object sender, RoutedEventArgs e)
 {
     TabItem CurrentTab = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TabItem;
     int index = TCWndLines.Items.IndexOf(CurrentTab);
     TextBox TBRename = new TextBox();
     TBRename.Tag = CurrentTab;
     TBRename.Text = CurrentTab.Header.ToString().Replace("__", "_");
     TBRename.LostFocus +=TBRename_LostFocus;
     TBRename.KeyDown +=TBRename_KeyDown;
     CurrentTab.Header = TBRename;
     TBRename.Select(0, TBRename.Text.Length);
     // тут необходимо передать фокус созданному TextBox
 }
开发者ID:okunokao,项目名称:GEoS,代码行数:13,代码来源:FormSourceItemsCache.xaml.cs

示例6: LoadAddLoginWPF

        private void LoadAddLoginWPF() {
            // define UI elements.
            Header = Properties_Resources.Where;

            System.Uri resourceLocater = new System.Uri("/DataSpaceSync;component/SetupAddLoginWPF.xaml", System.UriKind.Relative);
            UserControl LoadAddLoginWPF = Application.LoadComponent(resourceLocater) as UserControl;

            address_label = LoadAddLoginWPF.FindName("address_label") as TextBlock;
            address_box = LoadAddLoginWPF.FindName("address_box") as TextBox;
            address_help_label = LoadAddLoginWPF.FindName("address_help_label") as TextBlock;
            user_label = LoadAddLoginWPF.FindName("user_label") as TextBlock;
            user_box = LoadAddLoginWPF.FindName("user_box") as TextBox;
            user_help_label = LoadAddLoginWPF.FindName("user_help_label") as TextBlock;
            password_label = LoadAddLoginWPF.FindName("password_label") as TextBlock;
            password_box = LoadAddLoginWPF.FindName("password_box") as PasswordBox;
            password_progress = LoadAddLoginWPF.FindName("password_progress") as CircularProgressBar;
            password_help_label = LoadAddLoginWPF.FindName("password_help_label") as TextBlock;
            address_error_label = LoadAddLoginWPF.FindName("address_error_label") as TextBox;
            continue_button = LoadAddLoginWPF.FindName("continue_button") as Button;
            cancel_button = LoadAddLoginWPF.FindName("cancel_button") as Button;

            ContentCanvas.Children.Add(LoadAddLoginWPF);

            address_box.Text = (Controller.PreviousAddress != null) ? Controller.PreviousAddress.ToString() : String.Empty;

            if (Controller.saved_user == String.Empty || Controller.saved_user == null) {
                user_box.Text = DefaultEntries.Defaults.Name;
            } else {
                user_box.Text = Controller.saved_user;
            }

            TaskbarItemInfo.ProgressValue = 0.0;
            TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
            if (!DefaultEntries.Defaults.CanModifyUrl) {
                address_box.IsEnabled = false;
                address_box.Visibility = Visibility.Hidden;
                address_help_label.Visibility = Visibility.Hidden;
                address_label.Visibility = Visibility.Hidden;
            }

            if (Controller.PreviousAddress == null || Controller.PreviousAddress.ToString() == String.Empty) {
                address_box.Text = DefaultEntries.Defaults.Url;
            } else {
                address_box.Text = Controller.PreviousAddress.ToString();
            }
            address_box.Focus();
            address_box.Select(address_box.Text.Length, 0);

            // Actions.
            ControllerLoginInsertAction();
            Controller.CheckAddPage(address_box.Text);

            address_box.TextChanged += delegate {
                string error = Controller.CheckAddPage(address_box.Text);
                if (!String.IsNullOrEmpty(error)) {
                    address_error_label.Text = Properties_Resources.ResourceManager.GetString(error, CultureInfo.CurrentCulture);
                    address_error_label.Visibility = Visibility.Visible;
                } else {
                    address_error_label.Visibility = Visibility.Hidden;
                }
            };

            cancel_button.Click += delegate {
                ControllerLoginRemoveAction();
                Controller.PageCancelled();
            };

            string binding = Controller.saved_binding;
            if (binding == null) {
                binding = CmisRepoCredentials.BindingBrowser;
            }

            continue_button.Click += delegate {
                // Show wait cursor
                password_progress.Visibility = Visibility.Visible;
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                // Try to find the CMIS server (asynchronously)
                GetRepositoriesDelegate dlgt =
                    new GetRepositoriesDelegate(SetupController.GetRepositories);
                ServerCredentials credentials = new ServerCredentials() {
                    UserName = user_box.Text,
                    Password = password_box.Password,
                    Address = new Uri(address_box.Text),
                    Binding = binding,
                };
                IAsyncResult ar = dlgt.BeginInvoke(credentials, null, null);
                while (!ar.AsyncWaitHandle.WaitOne(100)) {
                    System.Windows.Forms.Application.DoEvents();
                }

                var result = dlgt.EndInvoke(ar);
                Controller.repositories = result.Repositories.WithoutHiddenOnce();

                address_box.Text = result.Credentials.Address.ToString();
                binding = result.Credentials.Binding;

                // Hide wait cursor
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                password_progress.Visibility = Visibility.Hidden;
//.........这里部分代码省略.........
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:101,代码来源:Setup.cs

示例7: SparkleSetup

        public SparkleSetup()
        {
            Controller.ShowWindowEvent += delegate {
               Dispatcher.BeginInvoke ((Action) delegate {
                    Show ();
                    Activate ();
                    BringIntoView ();
                });
            };

            Controller.HideWindowEvent += delegate {
                Dispatcher.BeginInvoke ((Action) delegate {
                    Hide ();
                });
            };

            Controller.ChangePageEvent += delegate (PageType type, string [] warnings) {
                Dispatcher.BeginInvoke ((Action) delegate {
                    Reset ();

                    switch (type) {
                    case PageType.Setup: {
                        Header      = "Welcome to SparkleShare!";
                        Description  = "First off, what's your name and email?\nThis information is only visible to team members.";

                        TextBlock name_label = new TextBlock () {
                            Text = "Full Name:",
                            Width = 150,
                            TextAlignment = TextAlignment.Right,
                            FontWeight = FontWeights.Bold
                        };

                        string name = System.Security.Principal.WindowsIdentity.GetCurrent ().Name;
                        name = name.Split ("\\".ToCharArray ()) [1];

                        TextBox name_box = new TextBox () {
                            Text  = name,
                            Width = 175
                        };

                        TextBlock email_label = new TextBlock () {
                            Text    = "Email:",
                            Width = 150,
                            TextAlignment = TextAlignment.Right,
                            FontWeight = FontWeights.Bold
                        };

                        TextBox email_box = new TextBox () {
                            Width = 175
                        };

                        Button cancel_button = new Button () {
                            Content = "Cancel"
                        };

                        Button continue_button = new Button () {
                            Content = "Continue",
                            IsEnabled = false
                        };

                        ContentCanvas.Children.Add (name_label);
                        Canvas.SetLeft (name_label, 180);
                        Canvas.SetTop (name_label, 200 + 3);

                        ContentCanvas.Children.Add (name_box);
                        Canvas.SetLeft (name_box, 340);
                        Canvas.SetTop (name_box, 200);

                        ContentCanvas.Children.Add (email_label);
                        Canvas.SetLeft (email_label, 180);
                        Canvas.SetTop (email_label, 230 + 3);

                        ContentCanvas.Children.Add (email_box);
                        Canvas.SetLeft (email_box, 340);
                        Canvas.SetTop (email_box, 230);

                        Buttons.Add (continue_button);
                        Buttons.Add (cancel_button);

                        name_box.Focus ();
                        name_box.Select (name_box.Text.Length, 0);

                        Controller.UpdateSetupContinueButtonEvent += delegate (bool enabled) {
                            Dispatcher.BeginInvoke ((Action) delegate {
                                continue_button.IsEnabled = enabled;
                            });
                        };

                        name_box.TextChanged += delegate {
                            Controller.CheckSetupPage (name_box.Text, email_box.Text);
                        };

                        email_box.TextChanged += delegate {
                            Controller.CheckSetupPage (name_box.Text, email_box.Text);
                        };

                        cancel_button.Click += delegate {
                            Dispatcher.BeginInvoke ((Action) delegate {
                                Program.UI.StatusIcon.Dispose ();
                                Controller.SetupPageCancelled ();
//.........这里部分代码省略.........
开发者ID:ianbogda,项目名称:SparkleShare,代码行数:101,代码来源:SparkleSetup.cs

示例8: tbstringfun

        //文本字符串处理
        private void tbstringfun(TextBox TB, int math, string ct)
        {
            switch (math)
            {      //插入处理
                case 0:
                    selectPos = TB.SelectionStart;
                    TB.Text = TB.Text.Substring(0, selectPos) + ct + TB.Text.Substring(selectPos);
                    selectPos += 1;
                    TB.Focus();
                    TB.Select(selectPos, 0);
                    break;
                //替换处理
                case 1:
                    selectPos = TB.SelectionStart;
                    TB.Text = TB.Text.Substring(0, selectPos - 1) + ct + TB.Text.Substring(selectPos);
                    TB.Focus();
                    TB.Select(selectPos, 0);
                    break;
                //删除一个字符
                case 2:
                    if (!string.IsNullOrEmpty(TB.Text))
                    {
                        selectPos = TB.SelectionStart;
                        if (selectPos != 0)
                        {
                            TB.Text = TB.Text.Substring(0, selectPos - 1) + TB.Text.Substring(selectPos);

                            selectPos -= 1;
                            TB.Focus();
                            TB.Select(selectPos, 0);
                        }
                    }
                    break;
                //清除文本
                case 3:
                    TB.Clear();
                    break;
            }
        }
开发者ID:Simulatio-of-Quanzhanyi,项目名称:moniquanzhanyi,代码行数:40,代码来源:Window_jianzhan7_DuoDian_new.xaml.cs

示例9: SetTextAndPos

 private void SetTextAndPos(TextBox tb, string text)
 {
     int pos = tb.SelectionStart;
     tb.Text = text;
     tb.Select(pos, 0);
 }
开发者ID:mdjabirov,项目名称:C1Decompiled,代码行数:6,代码来源:C1MaskedTextBoxPage.xaml.cs

示例10: SetSelectTextToEnd

 /// <summary>
 ///  将textbox中的光标移动到最后
 /// </summary>
 /// <param name="textbox"><see cref="TextBox"/></param>
 private static void SetSelectTextToEnd(TextBox textbox)
 {
     textbox.Select(textbox.Text.Length, textbox.Text.Length);
 }
开发者ID:someonehan,项目名称:HXZH.ToolsKit,代码行数:8,代码来源:IPTextBox.cs

示例11: Suggest

        private void Suggest(TextBox textBox, Regex matchAndReplace, int offset)
        {
            if (ignoreKey || friends == null) return;

            List<String> currentFriends = new List<string>();
            string selectedText = string.Empty;
            Match matchedText = Match.Empty;
            if (isInAutocompleteMode)
            {
                ignoreKey = true;
                selectedText = textBox.SelectedText;
                textBox.SelectedText = string.Empty;
                ignoreKey = false;
            }

            int length = textBox.Text.Length;
            isInAutocompleteMode = matchAndReplace.IsMatch(textBox.Text);
            if (!isInAutocompleteMode)
            {
                ShowStatus(string.Empty);
                return;
            }

            matchedText = matchAndReplace.Match(textBox.Text);
            int selectedIndex = 0;
            if (matchedText.Success)
            {
                string userEnteredText = matchedText.Groups[2].Value;
                {
                    foreach (User friend in friends)
                    {
                        if (friend.ScreenName.StartsWith(userEnteredText, StringComparison.CurrentCultureIgnoreCase) || userEnteredText.Length == 0)
                            currentFriends.Add(friend.ScreenName);
                    }
                }
                if (currentFriends.Count != 0)
                {
                    currentFriends.Sort();

                    selectedIndex = currentFriends.IndexOf(userEnteredText + selectedText);
                    if (selectedIndex < 0) selectedIndex = 0;
                    selectedIndex += offset;
                    if (selectedIndex < 0) selectedIndex = currentFriends.Count - 1;
                    else if (selectedIndex > (currentFriends.Count - 1)) selectedIndex = 0;

                    ignoreKey = true;
                    textBox.Text = matchAndReplace.Replace(textBox.Text, String.Format("${{1}}{0}", currentFriends[selectedIndex]));
                    textBox.Select(length, textBox.Text.Length - length);
                    ignoreKey = false;

                    ShowStatus(string.Format("{0} matching - [Up/Down] to cycle, [Tab] to select",currentFriends.Count));
                }
            }
        }
开发者ID:emuikernel,项目名称:wittytwitter,代码行数:54,代码来源:MainWindow.xaml.cs

示例12: BeginEditTextOnSelected

        internal void BeginEditTextOnSelected()
        {
            ItemLostFocus();

            selectedForEditing = (SelectedItem as DragDropTreeViewItem);

            if (selectedForEditing == null) return;

            TextBox tb = new TextBox();
            tb.LostFocus += tb_LostFocus;
            tb.KeyDown += tb_KeyDown;
            tb.Text = lastSelectedItem.Tag.ToString();
            tb.Focusable = true;

            (selectedForEditing.Header as StackPanel).Children.RemoveAt(2);
            (selectedForEditing.Header as StackPanel).Children.Add(tb);
            selectedForEditing.CanDrag = false;

            tb.Select(0, tb.Text.Length);
            tb.Focus();
        }
开发者ID:Alexz18z35z,项目名称:Gibbo2D,代码行数:21,代码来源:SceneHierarchyTreeView.xaml.cs

示例13: Main


//.........这里部分代码省略.........
            InterceptKeys.KeyDown +=
                key =>
                {
                    if (key == Key.LeftShift)
                    {
                        //w.Background = new SolidColorBrush(Color.FromArgb(2, 0, 0, 0));
                        //w.MakeInteractive(true);
                        NextInputModeEnabled = true;
                    }
                    else
                    {

                        if (NextInputModeEnabled || NextInputModeKeyDownEnabled)
                        {

                            NextInputModeKeyDownEnabled = false;
                            NextInputModeKeyDown(key);

                        }

                        NextInputModeEnabled = false;
                    }
                };
            #endregion

            #region KeyUp
            InterceptKeys.KeyUp +=
                key =>
                {
                    if (key == Key.CapsLock)
                    {
                        CommandKeysEnabled = !CommandKeysEnabled;
                        TopicText.IsReadOnly = CommandKeysEnabled;
                        TopicText.Select(0, 0);
                    }

                    if (key == Key.LeftShift)
                    {
                        NextInputModeKeyDownEnabled = false;
                    }
                    else
                    {

                    }

                    NextInputModeEnabled = false;
                };
            #endregion


            var s = 7;

            var ThumbnailSize = 0.4;
            var CaptionBackgroundHeight = 24;

            #region UpdateChildren
            Action UpdateChildren =
                delegate
                {
                    if (w.ActualWidth == 0)
                        return;

                    var ss = s;
                    var ss2 = 0;

开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:65,代码来源:Program.cs

示例14: LoadAddCustomizeWPF

        private void LoadAddCustomizeWPF() {
            string parentFolder = Controller.DefaultRepoPath;

            // UI elements.
            Header = Properties_Resources.Customize;

            System.Uri resourceLocater = new System.Uri("/DataSpaceSync;component/SetupAddCustomizeWPF.xaml", System.UriKind.Relative);
            UserControl LoadXAML = Application.LoadComponent(resourceLocater) as UserControl;

            localfolder_label = LoadXAML.FindName("localfolder_label") as TextBlock;
            localfolder_box = LoadXAML.FindName("localfolder_box") as TextBox;
            localrepopath_label = LoadXAML.FindName("localrepopath_label") as TextBlock;
            localrepopath_box = LoadXAML.FindName("localrepopath_box") as TextBox;
            localfolder_error_label = LoadXAML.FindName("localfolder_error_label") as TextBlock;

            choose_folder_button = LoadXAML.FindName("choose_folder_button") as Button;

            back_button = LoadXAML.FindName("back_button") as Button;
            continue_button = LoadXAML.FindName("continue_button") as Button;
            cancel_button = LoadXAML.FindName("cancel_button") as Button;

            // init UI elements.
            string localfoldername = Controller.saved_address.Host.ToString();
            foreach (var repository in Controller.repositories) {
                if (repository.Id == Controller.saved_repository) {
                    localfoldername += "\\" + repository.Name;
                    break;
                }
            }

            localfolder_box.Text = localfoldername;
            localrepopath_box.Text = Path.Combine(parentFolder, localfolder_box.Text);

            ContentCanvas.Children.Add(LoadXAML);

            localfolder_box.TextChanged += delegate {
                try {
                    localrepopath_box.Text = Path.Combine(parentFolder, localfolder_box.Text);
                } catch (Exception) {
                }
            };

            TaskbarItemInfo.ProgressValue = 0.0;
            TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;

            // Actions.
            ControllerCustomizeInsertAction();

            // Repo path validity.
            CheckCustomizeInput(localfolder_box, localrepopath_box, localfolder_error_label);

            localfolder_box.Select(localfolder_box.Text.Length, 0);
            localfolder_box.Focus();

            localfolder_box.TextChanged += delegate {
                CheckCustomizeInput(localfolder_box, localrepopath_box, localfolder_error_label);
            };

            localrepopath_box.TextChanged += delegate {
                CheckCustomizeInput(localfolder_box, localrepopath_box, localfolder_error_label);
            };

            // Choose a folder.
            choose_folder_button.Click += delegate {
                System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
                if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                    parentFolder = folderBrowserDialog1.SelectedPath;
                    localrepopath_box.Text = Path.Combine(parentFolder, localfolder_box.Text);
                }
            };

            // Other actions.
            cancel_button.Click += delegate {
                ControllerCustomizeRemoveAction();
                Controller.PageCancelled();
            };

            back_button.Click += delegate {
                ControllerCustomizeRemoveAction();
                Controller.BackToPage2();
            };

            continue_button.Click += delegate {
                ControllerCustomizeRemoveAction();
                Controller.CustomizePageCompleted(localfolder_box.Text, localrepopath_box.Text);
            };
        }
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:87,代码来源:Setup.cs

示例15: OnApplyTemplate

        /// <summary>
        /// When overridden in a derived class, is invoked whenever 
        /// application code or internal processes call ApplyTemplate
        /// </summary>
        public override void OnApplyTemplate()
        {
            if (textBoxTemplated != null)
            {
                textBoxTemplated.PreviewKeyDown -= OnTextBoxTemplatedKeyDown;
                textBoxTemplated.SelectionChanged -= OnTextBoxTemplatedSelectionChanged;
                textBoxTemplated.LostFocus -= OnTextBoxTemplatedLostFocus;
                textBoxTemplated.GotKeyboardFocus -= OnTextBoxTemplatedGotKeyboardFocus;
                textBoxTemplated.TextChanged -= OnTextBoxTemplatedTextChanged;
                BindingOperations.ClearAllBindings(textBoxTemplated);
            }
            textBoxTemplated = GetTemplateChild("PART_TextBox") as System.Windows.Controls.TextBox;
            

            // Check template
            if (!IsTemplateValid())
            {
                Debug.WriteLine("Template for TextBox control is invalid");
                return;
            }

            textBoxTemplated.Text = Text;
            textBoxTemplated.Select(textBox.SelectionStart, textBox.SelectionLength);

            // Bindings
            BindingOperations.ClearAllBindings(textBox);

            Binding binding = new Binding("Text");
            binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            binding.Source = this;
            binding.Mode = BindingMode.TwoWay;
            textBoxTemplated.SetBinding(System.Windows.Controls.TextBox.TextProperty, binding);

            Bind(this, textBoxTemplated, "CharacterCasing", System.Windows.Controls.TextBox.CharacterCasingProperty, BindingMode.TwoWay);
            Bind(this, textBoxTemplated, "MaxLength", System.Windows.Controls.TextBox.MaxLengthProperty, BindingMode.TwoWay);
            Bind(this, textBoxTemplated, "TextAlignment", System.Windows.Controls.TextBox.TextAlignmentProperty, BindingMode.TwoWay);
            Bind(this, textBoxTemplated, "TextDecorations", System.Windows.Controls.TextBox.TextDecorationsProperty, BindingMode.TwoWay);
            Bind(this, textBoxTemplated, "IsUndoEnabled", System.Windows.Controls.TextBox.IsUndoEnabledProperty, BindingMode.TwoWay);
            Bind(this, textBoxTemplated, "UndoLimit", System.Windows.Controls.TextBox.UndoLimitProperty, BindingMode.TwoWay);
            Bind(this, textBoxTemplated, "AutoWordSelection", System.Windows.Controls.TextBox.AutoWordSelectionProperty, BindingMode.TwoWay);
#if NET35
#else
            Bind(this, textBoxTemplated, "SelectionBrush", System.Windows.Controls.TextBox.SelectionBrushProperty, BindingMode.TwoWay);
            Bind(this, textBoxTemplated, "SelectionOpacity", System.Windows.Controls.TextBox.SelectionOpacityProperty, BindingMode.TwoWay);
            Bind(this, textBoxTemplated, "CaretBrush", System.Windows.Controls.TextBox.CaretBrushProperty, BindingMode.TwoWay);
#endif
            Bind(this, textBoxTemplated, "IsReadOnly", System.Windows.Controls.TextBox.IsReadOnlyProperty, BindingMode.TwoWay);


            textBoxTemplated.PreviewKeyDown += OnTextBoxTemplatedKeyDown;
            textBoxTemplated.SelectionChanged += OnTextBoxTemplatedSelectionChanged;
            textBoxTemplated.LostFocus += OnTextBoxTemplatedLostFocus;
            textBoxTemplated.GotKeyboardFocus += OnTextBoxTemplatedGotKeyboardFocus;
            textBoxTemplated.TextChanged += OnTextBoxTemplatedTextChanged;
        }
开发者ID:Gainedge,项目名称:BetterExplorer,代码行数:59,代码来源:TextBox.cs


注:本文中的System.Windows.Controls.TextBox.Select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。