我构建一个DataGrid包含一个自定义ComboBoxColumn,当我用鼠标选择它时显示和选择适当的字段,但在ComboBox丢失后重置为列表中的第一项焦点。此外,当我从Excel电子表格导入数据时,ComboBox不会更改为与工作表中的值匹配。导入数据到DatagridComboBoxColumn不更新组合列表值
注:我打算重用这个类来为不同的数据创建一系列ComboBoxes。
什么阻止组合框接受新值?
ComboList类
namespace x.Models
{
public class ComboList
{
public int FieldID {get;set;}
public string FieldString {get;set;}
}
}
XAML组合框代码
<DataGridComboBoxColumn Header="Platform Type" x:Name="PlatformTable" SelectedValueBinding="{Binding FieldID}" DisplayMemberPath="FieldString" SelectedValuePath="1" />
代码(后面)
public partial class MainWindow: Window
{
public ObservableCollection<Models.ComboList> PlatformCombo {get;set;}
public MainWindow()
{
PlatformCombo = new ObservableCollection<Models.ComboList>()
{
new Models.ComboList() {FieldID=1,FieldString="Mounted"},
new Models.ComboList() {FieldID=2,FieldString="Dismounted"}
};
PlatformTable.ItemsSource = PlatformCombo;
}
示例Excel数据
Platform Type
1
2
我已经加入UpdateSourceTrigger和模式的SelectedValueBinding,但我看到了同样的问题: 'SelectedValueBinding = “{结合FieldID,UpdateSourceTrigger =的PropertyChanged,模式=双向}”' – Kahlan