Observable集合中的更改未反映在UI中

Rel*_*ity 2 data-binding wpf observablecollection

我有一个类型"Observable collection"...当我添加一个项目时,它不是在UI中反映出来的......我做错了什么......?

<ComboBox Grid.Column="0" Grid.Row="3" 
Width="120" SelectedIndex="0"
Margin="5,0,0,0" HorizontalAlignment="Left"
ItemsSource="{Binding AllPlaces}" 
DisplayMemberPath="PlaceName" 
SelectedItem="{Binding Path=SelectedPlace.Value, Mode=TwoWay}" 
VerticalAlignment="Top">
</ComboBox>


// Add the new item to the existing place list, so that it will be refreshed.
ObservableCollection<PlaceDto> existingPlaceList = new ObservableCollection<PlaceDto>();
// Copy all places to a temperory list.
foreach(PlaceDto placeItem in AllPlaces)
{
existingPlaceList.Add(placeItem);
}
// Add new place to existing list
existingPlaceList .Add(newPlace);
AllPlaces= existingPlaceList;
Run Code Online (Sandbox Code Playgroud)

Joe*_*csy 5

如果列表发生更改,ObservableCollection将通知GUI.但是,您正在使用AllDivisions = existingPlaceList行更改整个列表本身.您必须为包含AllDivisions属性的类实现INotifyPropertyChanged,以便在换出列表时告诉GUI.