void SiteRDEControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { var site = DataContext as RDESiteViewModel; if (site != null) { if (_currentSite != null) { // although the database actions are registered for new/modified traits, we need to keep track of them so we can // redisplay them as the user flips around the different sites. _currentSite.Traits = _traits.GetModel(); } _traits.BindModel(site.Traits, site); _currentSite = site; // There is a datacontext change cascade problem here. // When the RDE frame advances/retreats its first changes the data context on the various RDE Panels (this one included) // but our downstream dependents have yet to have their datacontexts changed (e.g. the position control, and it's descendants // still point to the old site). This means when we clear the control (several lines down), it was actually clearing the old site as well as the control // text boxes. So the datacontext for the position control is explicitly set here so that it is correctly bound to the new site // when it is cleared. // NOTE: have tried dispatching the call (kind of like invokeLater) and it didn't work. ctlPosition.DataContext = site; if (!site.Latitude.HasValue || !site.Longitude.HasValue || (site.Latitude.Value == 0 && site.Longitude.Value == 0)) { ctlPosition.Clear(); } } }
void MaterialRDEControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { var mat = DataContext as RDEMaterialViewModel; if (mat != null) { this.IsEnabled = true; if (_currentMaterial != null) { // although the database actions are registered for new/modified traits, we need to keep track of them so we can // redisplay them as the user flips around the different material. _currentMaterial.Traits = _traits.GetModel(); _currentMaterial.Multimedia = _multimedia.GetModel(); } _traits.BindModel(mat.Traits, mat); _currentMaterial = mat; _multimedia.BindModel(mat.Multimedia, mat); grpSubParts.Items = _currentMaterial.SubParts; _subpartsFull.SetModel(_currentMaterial, _currentMaterial.SubParts); _associates.SetModel(_currentMaterial, _currentMaterial.Associates); } else { this.IsEnabled = false; } }