internal void ChangeStatus(DeviceViewModel clickedDevice = null) { if (SelectedDevice != null && (SelectedDevice == clickedDevice || clickedDevice == null)) { var device = Context.Current.Devices.FirstOrDefault(x => x.Title == SelectedDevice.Title); if (device != null) { device.UpdateValue(!Convert.ToBoolean(SelectedDevice.Status)); } } }
public DevicesViewModel() { Devices = new ObservableCollection <DeviceViewModel>(); lock (Context.Current.Locks["Devices"]) { foreach (var device in Context.Current.Devices) { if (device != null) { var devVM = new DeviceViewModel() { Title = device.Title, Status = Convert.ToInt32(device.Status) }; Devices.Add(devVM); } } CollectionHandler <DeviceViewModel> handler = new CollectionHandler <DeviceViewModel>(Devices, SelectedDevice); Context.Current.Devices.CollectionChanged += handler.Devices_CollectionChanged; } }