开发者

Check a IList changed?

I am trying to make 开发者_StackOverflow社区an appointment book in Silverlight with C#, so I will have a main AppointmentBook control, with follows to store each of the Appointment control:

    List<kAppointment> appointments = null;

    public IList<kAppointment> Appointments
    {
        get
        {
            if (appointments == null)
            {
                appointments = new List<kAppointment>();
            }

            // Can notify something change here, 
            return appointments;
        }
    }

I can notify the AppointmentBook control new list assigned with above code, so it will redraw each of the appointments control.

But how can I check it if the appointment list is changed by the follows?:

appointments.Add(NewAppointment);


Sounds like a job for ObservableCollection.

This lets us subscribe to events and tells us in what way the collection changed.


You can use and ObservableCollection like the others suggest or you can do some encapsulation and not provide complete access to a private member.

If the Add is done through a single public method that you provide you will always know when users of the class are adding appointments and act accordingly.


I can think of a few things.

  1. Make a wrapperclass for the IList that contains an extra boolean changed.
  2. Use some variable (a boolean for instance) that you make true when you do an add/remove/edit action, and make it false again when you did the redraw.
  3. Keep a copy of the list your're drawing (or only of some index that are present) and check if the 'incoming' and 'last drawed' list are the same
  4. Use an ObservableCollection
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜