海我找到了解决方案..
2 things to be happened here..
1)我在员工中有所有获取的数据结果。因此,如果我从组合框中选择了任何值,我需要将所选结果绑定到数据网格中。为此,我们需要使用Employees.Clear() 方法清除Employees。之后使用 Foreach 循环访问“semp”并返回值..
2) 现在Employees 只包含一个组合框选择值。所以Datagrid 和ComboBox 只显示一个值。如何克服.. 结果如下。
XAML:
<ComboBox ItemsSource="{Binding disemp}" DisplayMemberPath="Dept" SelectedItem="{Binding Names, Mode=TwoWay}" Margin="130,117,0,0" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<si:CallDataMethod Method="BindNew"/>
<si:SetProperty TargetName="LayoutRoot"/>
</i:EventTrigger>
<i:EventTrigger EventName="Loaded">
<si:CallDataMethod Method="Selnew"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
视图模型:
public IList<Employee> Employees { get; private set; }
public ObservableCollection<Employee> disemp { get; private set; }
public ObservableCollection<Employee> dgrids { get; private set; }
public ObservableCollection<Employee> EmployeeCopy{ get; private set; }
public EmployeeListViewModel()
{
Employees = Silverlight_MVVM.DataHelper.EmployeeDataHelper.EmployeeData ();
disemp = Silverlight_MVVM.DataHelper.EmployeeDataHelper.Employeedist();
dgrids=Silverlight_MVVM.DataHelper.EmployeeDataHelper.dgrid();
}
public void BindNew()
{
Employee emplo = new Employee();
Employees = Silverlight_MVVM.DataHelper.EmployeeDataHelper.EmployeeData();
EmployeeCopy = dgrids.ToList ();
string name = Names.Dept.ToString();
var semp = from emp in EmployeeCopy where emp.Dept.Equals(name) select emp;
List<Employee> lt = new List<Employee>();
lt = semp.ToList();
lt.Count();
//int i;
Employees.Clear();
for (int i = 0; i < lt.Count(); i++)
{
emplo.Fname = lt[0].Fname.ToString();
emplo.Sname = lt[0].Sname.ToString();
emplo.Dept = lt[0].Dept.ToString();
Employees.Add(emplo);
}
RaisePropertyChanged("Employees");
}
}
我添加了虚拟 ObservableCollections.. 仅此而已.. 问题已解决..