Chuanzhi podcast -- WPF basic video learning -- sender explanation, -- wpf -- sender

Source: Internet
Author: User

Chuanzhi podcast -- WPF basic video learning -- sender explanation, -- wpf -- sender

Sender is the object that fires the event. If it is used in the double-click event of the Button, it is only the currently clicked object.

For example, there are two Button controls: 1 and 2, respectively, and a Button_Click event is bound.

Private void Button_Click (object sender, RoutedEventArgs e) {Button btn = (Button) sender; btn. Content = "you have clicked on me !! ";}

When you click the first button1

When you click Button2

It can be seen that sender refers to the currently activated control.

 


How to obtain all specific types of files under the path and bind them to the treeview

Front:
<Grid>
<TreeView Name = "tvDirectories" ItemsSource = "{Binding}">
</TreeView>
<Button Content = "Button" Height = "23" HorizontalAlignment = "Left" Margin = "401,276, 0, 0 "Name =" button1 "verticalignment =" Top "Width =" 75 "Click =" button#click "/>
</Grid>
Background:
Private void button#click (object sender, RoutedEventArgs e)
{
Var list = new List <string> ();
String path = @ "D: \ Software installer \ Application Software \"; // folder path
If (Directory. Exists (path) // determines whether the Directory file to be saved Exists.
{
Var directory = new DirectoryInfo (path );
FileInfo [] collection = directory. GetFiles ("*. exe"); // specifies the type
Foreach (FileInfo item in collection)
{
String fullname = item. Name. ToString ();
String filename = fullname. Substring (0, fullname. LastIndexOf ("."); // remove the suffix.
List. Add (filename );
}
TvDirectories. DataContext = list;
}
Else
{
MessageBox. Show ("the folder does not exist! ");
}
}





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.