I have a WPF / XAML form data-bound to a property in a dictionary, similar to this:
<TextBox Text="{Binding Path=Seat[2B].Name}">
Seat
is exposed as a property IDictionary<String, Reservation>
on the airplane object.
class airplane
{
private IDictionary<String, Reservation> seats;
public IDictionary<String, Reservation> Seat
{
get { return seats; }
// set is not allowed
}
}
From within the code of my Window, the value of seat 2B is sometimes changed, and after that, I want to notify the UI that the property has changed.
class MyWindow : Window
{
private void AddReservation_Click(object sender, EventArgs e)
{
airplane.Seat["2B"] = new Reservation();
// I want to override the assignment operator (=)
// of the Seat-dictionary, so that the airplane will call OnNotifyPropertyChanged.
}
}
I've looked to see if the Dictionary is IObservable
, so that I could observe changes to it, but it doesn't seem to be.
Is there any good way to "catch" changes to the dictionary in the airplane-class so that I can NotifyPropertyChanged
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…