如图,第一行选择了配方之后,第二行再选择配方的时候需要更新下拉框,下拉框更新后却把第一行已经选择的数据给清除了。后台是将下拉框的ObservableCollection集合clear之后重新赋值刷新下拉框。如何解决?
<DataGridTemplateColumn Header="钻井液配方" HeaderStyle="{StaticResource columnHeaderCenter}" Width="200">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox IsEditable="True"
Text="{Binding Composition,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding DataContext.Composition_list,Mode=Default, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="DropDownOpened">
<command:EventToCommand CommandParameter="{Binding Id}" Command="{Binding DataContext.DropDownCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}"/>
</i:EventTrigger>
<i:EventTrigger EventName="DropDownClosed">
<command:EventToCommand CommandParameter="{Binding Id}" Command="{Binding DataContext.SelectionChangedCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
//刷新下拉框数据
public void Refresh_list(int id)
{
var fluidMaintainanceDatas = DataBase.GetFluidMaintainanceDatas();
var performanceDatas=DataBase.GetDrillingFluidPerformanceDatas();
var system = performanceDatas[id].DrillingFluidSystem;
var temp = fluidMaintainanceDatas.Where(t => t.DrillingFluidSystem == system);
var compositionDatas = temp.Select(t => t.Composition);
Composition_list.Clear();
foreach (var compositionData in compositionDatas)
{
Composition_list.Add(compositionData);
}
}