我是MVVM的新手。我在我的項目中使用wpf和MVVM。所以我現在正在測試一些東西,然後潛入我需要編寫的應用程序中。當AutoGenerateColumns =「True」時,如何使datagrid的特定列成爲combobox
我的頁面(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));
}
}
}
DataGrid的綁定成功的數據表。現在我在數據網格中有一列「性別」。這應該是一個組合框,coobobox的項目源來自視圖模型的GenderDataTable。我怎樣才能做到這一點?
Infragistics的網格不支持這個活動? wat爲dat case做? –
好吧,如果它不支持任何等效事件,我會聯繫Infragistics詢問他們有什麼問題,然後繼續禁用列的auotgeneration並明確地定義它們。 – Dtex
您真的幫助了我。非常感謝。 – perozzo