嗨,当我试图绑定一个组合框时,我对silverlight很新,在ItemsSource和DisplayMemberPath中有3个项目作为“JobName”但是值没有被绑定。
这是我的代码如下。
xaml:
<combobox x:name="cbJobName" grid.column="1" grid.row="1" margin="5,5,0,10" horizontalalignment="Left" style="{StaticResource ComboBoxStyle2}" width="200" maxwidth="250" height="23" maxdropdownheight="250" tooltipservice.tooltip="Select a Job" selectionchanged="cbJobName_SelectionChanged">
</combobox>
代码背后:
JobNames = new List<JobList>();
JobList Jobs = new JobList();
Jobs.jobID = 1;
Jobs.jobName = "DM Propagation";
Jobs.errorMessage = "";
Jobs.lastDate = "1/11/2014";
Jobs.nextDate = "2/11/2014";
Jobs.jobState = 1;
JobNames.Add(Jobs);
Jobs = new JobList();
Jobs.jobID = 2;
Jobs.jobName = "Import Propagation";
Jobs.errorMessage = "";
Jobs.jobState = 2;
Jobs.lastDate = "3/11/2014";
Jobs.nextDate = "4/11/2014";
JobNames.Add(Jobs);
Jobs = new JobList();
Jobs.jobID = 3;
Jobs.jobName = "Cross Propagation";
Jobs.errorMessage = "";
Jobs.jobState = 2;
Jobs.lastDate = "5/11/2014";
Jobs.nextDate = "6/11/2014";
JobNames.Add(Jobs);
cbJobName.ItemsSource = JobNames;
cbJobName.DisplayMemberPath = "jobName";
cbJobName.SelectedIndex = 0;
biJobProcessingHome.IsBusy = false;
答案 0 :(得分:0)
我认为你在制作名单时犯了一个错误,你走了,
在xaml中,
<ComboBox Height="23" HorizontalAlignment="Left" Margin="188,150,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" />
假设您有一个名为Job的小组,
public class Job
{
public int JobID { get; set; }
public string jobName { get; set; }
public string errorMessage { get; set; }
public DateTime lastDate { get; set; }
public DateTime nextDate { get; set; }
public int status { get; set; }
}
这是如何绑定它的,
List<Job> JobsList = new List<Job>();
for (int i = 0; i < 5; i++)
{
Job jobObj = new Job();
jobObj.JobID = i;
jobObj.jobName = "test" + i;
jobObj.status = 1;
jobObj.errorMessage = "success";
JobsList.Add(jobObj);
}
comboBox1.ItemsSource = JobsList;
comboBox1.DisplayMemberPath = "jobName";