Previewmouseleftbuttonup events for textbox in WPF

Source: Internet
Author: User

When using the TextBox's Previewmouseleftbuttonup event (for example, when the mouse clicks into the textbox, clearing the current input), it is very surprising to find that no matter how many clicks can not click on the other controls, the focus has been occupied by the text box.

The solutions and test cases are as follows:

Interface

1 <Windowx:class= "LEARNWPF." MainWindow "2 xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"3 xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"4 Title= "MainWindow"Height= " the"Width= "525">5     <Grid>6         <ListBox>7             <TextBoxx:name= "TextBox"Previewmouseleftbuttonup= "Textbox_previewmouseleftbuttonup"Text= "Test text"Width= "Max"Height= "+"/>8             <Buttonx:name= "BTN"Click= "Btn_click"Width= "+"Height= "+" />9         </ListBox>Ten     </Grid> One </Window>

Logic

1 usingSystem.Windows;2 usingSystem.Windows.Controls;3 usingSystem.Windows.Input;4 5 namespaceLEARNWPF6 {7     /// <summary>8     ///Interaction logic for MainWindow.xaml9     /// </summary>Ten      Public Partial classMainwindow:window One     { A          PublicMainWindow () -         { - InitializeComponent (); the         } -  -         Private voidBtn_click (Objectsender, RoutedEventArgs e) -         { +MessageBox.Show ("Button ' s clicked"); -         } +  A         Private voidTextbox_previewmouseleftbuttonup (Objectsender, MouseButtonEventArgs e) at         { -Textbox. Text =string. Empty; -e.handled =true; -             //to remove a textbox from capturing a mouse - (textbox). Releasemousecapture (); -         } in     } -}

Previewmouseleftbuttonup events for textbox in WPF

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.