我是新来MVVM。 我在我的项目使用WPF与MVVM。 所以我现在测试的东西之前,跳水到一个应用程序需要编写。
我的页面(EmpDetailsWindow.xaml)是这样的
<Grid>
<DataGrid Name="dgEmployee" Grid.Row="0" AutoGenerateColumns="True" ItemsSource="{Binding EmployeeDataTable}" CanUserAddRows="True" CanUserDeleteRows="True" IsReadOnly="False" />
<Button x:Name="btnSubmit" Content="Submit" Command="{Binding SubmitCommand}" CommandParameter="sample param" HorizontalAlignment="Left" Margin="212,215,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
和我的模型(EmpDetailsWindowViewModel)是如下
public class EmpDetailsWindowViewModel : INotifyPropertyChanged
{
public ICommand SubmitCommand { get; set; }
public EmpDetailsWindowViewModel()
{
EmployeeDataTable = DataTableCreator.EmployeeDataTable();
GenderDataTable = DataTableCreator.GenderDataTable();
SubmitCommand = new SubmitCommand();
}
DataTable _employeeDataTable;
public DataTable EmployeeDataTable
{
get { return _employeeDataTable;}
set
{
_employeeDataTable = value;
RaisePropertyChanged("EmployeeDataTable");
}
}
DataTable _genderDataTable;
public DataTable GenderDataTable
{
get { return _genderDataTable; }
set
{
_genderDataTable = value;
RaisePropertyChanged("GenderDataTable");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
数据网格绑定成功的数据表。 现在,我在数据网格列“性别”。 这应该是一个组合框和cobobox的项目源从视图模型的GenderDataTable了。 我怎样才能做到这一点?