I have DataGridComboBoxColumn in DataGrid:
<DataGridComboBoxColumn Header="{x:Static Properties:Resources.Unit}" Width="Auto"
SelectedValueBinding="{Binding UnitUnitId}"
SelectedValuePath="UnitId"
DisplayMemberPath="Name" >
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource" Value="{Binding Path=DataContext.Units,RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource" Value="{Binding Path=DataContext.Units,RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
和ComboBox:
<ComboBox x:Name="unitBox" ItemsSource="{Binding Path=Units}"
SelectedItem="{Binding TaxSubGroup.Unit}"
Grid.Row="2"
Grid.Column="1" Margin="11,11,0,0" HorizontalAlignment="Stretch">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={x:Static c:UnitToStringConverter.Default}}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
单位财产:
public ObservableCollection<Unit> Units
{
get
{
return _units;
}
set
{
if(_units!=value)
{
_units = value;
RaisePropertyChanged("Units");
}
}
}
i m 改变ComboBoxes值时,数据GridComboBoxColum 自动更新其价值,但数据Grid s combo Boxcolumn的数值没有更新ComboBoxes值。 为什么?
附文
问题在于数据GridComboBoxCulumn s SelectedValueBled property。 所需要的是增加更新财产:
SelectedValueBinding="{Binding UnitUnitId,UpdateSourceTrigger=PropertyChanged}"