1: Create a new WPF project and add a ListBox control to the XAML file as follows:
<window x:class= "Listbinding.window1" xmlns= "Http://schemas.microsoft.com/winfx /2006/xaml/presentation " xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml " title= "Window1" height= " width=" > <Grid> <ListBox /> </Grid> </Window> 2: Add a class to the CS file, and in its constructor get the name of the system when it is running, the code is as follows: using system.collections.generic; using system.windows; namespace listbinding { /// <summary> /// Interaction logic for window1.xaml /// </summary> public partial class window1 : window { public window1 () &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp; { initializecomponent (); } } public class Processes : List<string> { public processes () { //gets the name of the process in the system and adds it to the class in the constructor System.Diagnostics.Process[] pList = System.Diagnostics.Process.GetProcesses (); foreach ( System.diagnostics.process p in plist) { this. ADD (p.processname); } } } 3: The following binding of the control to the data, the contents of the modified XAML file are as follows: <window x:class= " Listbinding.window1 " xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml" xmlns: Src= "clr-namespace:listbinding" title= "Window1" height= "" " width=" > <Window.Resources> &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;<SRC: processes x:key= "P"/> </Window.Resources> <grid > <listbox itemssource= "{StaticResource p}"/ > </Grid> </Window> in the above content, a namespace src is added, which represents the space defined in the CS file listbinding , and then with the resourcesMethod adds the name of all processes to the listbox.
This completes the binding between the ListBox and the process name.
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.