我有一个datagrid,在celltemplate中有一个组合框
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Path=List,Mode=TwoWay}">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding Path=ID,Mode=TwoWay}"></DataGridTextColumn>
<DataGridTemplateColumn Header="Names" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox SelectedItem="{Binding Path=Name,Mode=TwoWay}"
SelectedValuePath="Type"
ItemsSource="{Binding Path=Names,Mode=TwoWay,Source={StaticResource someSource}}"></ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
在上面的代码中,当我从数据网格中的组合框中更改名称时,项目源列表应该更改??如何做???
答案 0 :(得分:0)
基于标题,我假设您的意思是更改Datagrid的itemsSource
。这是一个奇怪的要求,但这应该有效
<ComboBox DropDownClosed="ComboBox_DropDownClosed"
SelectedItem="{Binding Path=Name,Mode=TwoWay}"
SelectedValuePath="Type"
ItemsSource="{Binding Path=Names,Mode=TwoWay,Source={StaticResource someSource}}">
</ComboBox>
private void ComboBox_DropDownClosed(object sender, EventArgs e)
{
myGrid.ItemsSource = myOtherList;
}