今天嘗試了下ComboBox的簡單綁定,大概步驟如下:
1. 準備數據 -c#
public System.Collections.ArrayList ComboBoxSource()
{
System.Collections.ArrayList list = new System.Collections.ArrayList();
for (int i = 0; i < 10; i++)
{
list.Add("Item"+i);
}
return list;
}
2. 把ComboBox數據源設置成Binding - xamal
<ComboBox x:Name="cboList" ItemsSource="{Binding}" SelectedIndex="0" Margin="3"/>
3. ComboBox數據源綁定 - c#
public MainWindow()
{
InitializeComponent();
this.cboList.DataContext = ComboBoxSource();
}
結果如下:
<img src="https://img-blog.csdn.net/20140918232027359?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvRGFubnlfWWFv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />