我有我的观点一个数据网格。 其中一列是的ItemSource通过静态资源绑定到一个列表在我看来模型datagridcomboboxcolumn。 问题是,当我在一行中改变所选择的项目,同一项目上的其他行选择。
视图模型
public class MyViewModel
{
private ObservableCollection<Wavelength> wlList = new ObservableCollection<Wavelength>();
private ObservableCollection<Model.AcquisitionParameters> acquisitionList = new ObservableCollection<Model.AcquisitionParameters>();
public ObservableCollection<Model.AcquisitionParameters> AcquisitionList
{
get { return acquisitionList; }
set { acquisitionList = value; OnPropertyChanged("AcquisitionList"); }
}
public ObservableCollection<Model.Wavelength> Wavelengths
{
get { return wavelengths; }
set { wavelengths = value; }
}
}
视图
<UserControl.Resources>
<CollectionViewSource Source="{Binding Wavelengths}" x:Key="wlList" />
</UserControl.Resources>
<DataGrid AutoGenerateColumns="False"
ItemsSource="{Binding Path=AcquisitionList, UpdateSourceTrigger=PropertyChanged}"
CanUserAddRows="True" CanUserDeleteRows="True" SelectionUnit="FullRow">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="Wavelength" Width="SizeToHeader"
SelectedValueBinding="{Binding Wavelength}"
SelectedValuePath="Value"
ItemsSource="{Binding Source={StaticResource wlList}}"
EditingElementStyle="{StaticResource StandardComboBox}"
ElementStyle="{StaticResource StandardComboBox}" />
</DataGrid.Columns>
</DataGrid>
波长
public class Wavelength
{
private double wavelength;
public double Value
{
get { return wavelength; }
set { wavelength = Value; }
}
public Wavelength(double wl)
{
this.wavelength = wl;
}
public override string ToString()
{
return string.Format("{0:0} nm", wavelength * 1e9);
}
}