1:æ°å»ºä¸ä¸ªWPFå·¥ç¨ï¼å¹¶å¨XAMLæ件ä¸æ·»å ä¸ä¸ªListBoxæ§ä»¶ï¼å¦ä¸ï¼
<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="800" Width="300"> çªå£1 é«åº¦ 宽度
<Grid>
<ListBox />
</Grid>
</Window>
2ï¼å¨csæ件ä¸æ·»å ä¸ä¸ªç±»ï¼å¹¶å¨å
¶æé å½æ°ä¸è·åç³»ç»å½æ£å¨è¿è¡çè¿ç¨çå称ï¼ä»£ç å¦ä¸ï¼
using System.Collections.Generic;
using System.Windows;
namespace ListBinding
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
}
public class Processes : List<string>
{
public Processes()
{
//å¨æé å½æ°ä¸åå¾ç³»ç»ä¸è¿ç¨çå称并å°å
¶æ·»å å°ç±»ä¸
System.Diagnostics.Process[] pList = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process p in pList)
{
this.Add(p.ProcessName);
}
}
}
}
3ï¼ä¸é¢è¦è¿è¡æ§ä»¶ä¸æ°æ®çç»å®ï¼ä¿®æ¹åçXAMLæ件å
容å¦ä¸ï¼
<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="800" Width="300">
<Window.Resources>
<src:Processes x:Key="p"/>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{StaticResource p}"/>
</Grid>
</Window>