c# - ObservableCollection not always updating UI and variable change incorrectly -


i have following viewmodel , in code link items control. when use line such as:

onoffschedule.dc.schedules[0].days[0].data[0] = 9; 

it updates ui sometimes?? , when updates data wrong. instead of assign first schedule, first day, , first time slot 9. updates first schedule (for days??) first time slot.

so trying figure out why updates every index in days array instead of first one.

thanks in advance!

public class schedulevm {     public observablecollection<schedule> schedules { get; set; }      private static schedulevm viewmodel = null;      public static schedulevm getinstance()     {         if (viewmodel == null)             viewmodel = new schedulevm();          return viewmodel;     }      private schedulevm()     {         schedules = new observablecollection<schedule>();          (byte = 0; < 32; i++)             schedules.add(new schedule());     } }  public class schedule {     public observablecollection<day> days { get; set; }      public schedule()     {         days = new observablecollection<day>();          int[] values = new int[96];          (byte = 0; < 96; i++)             values[i] = 3;          (byte = 0; < 8; i++)             days.add(new day() { data = values });     } }  public class day : basevm {     private int[] _data;     public int[] data     {                 {             return _data;         }         set         {             _data = value;             onpropertychanged("data");         }     } } 

below view goes along code. user control create inside window (and inside window user control called 'onoffschedule'.

public schedulevm dc { get; private set; }      public schedule()     {         initializecomponent();          dc = schedulevm.getinstance();         this.datacontext = dc;          schedule.itemssource = dc.schedules[0].days;     } 

onoffschedule.dc.schedules[0].days[0].data[0] = 9; 

that line not trigger update under normal circumstances. you're doing setting integer in integer array:

public int[] data { ... } 

you put onpropertychanged call in there when entire array changes. when set 1 of values, wpf doesn't know occurred.

you have right idea using observablecollection<day> on other class. need similar in day class data property.


Comments