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! ");
}
}