private static void ReEvaluateIdPath(DependencyObject element) { PersistentProperty.ClearIdPath(element); //Get (inherited) parent path string ParentIdPath = PersistentProperty.GetIdPath(element); string Id = PersistentProperty.GetId(element); if (Id != null) { //Compute and set new path PersistentProperty.SetIdPath(element, ParentIdPath != null ? $"{ParentIdPath}.{Id}" : Id); } PersistentProperty.NotifyChildrenThatIdPathChanged(element); }
private static void NotifyChildrenThatIdPathChanged(DependencyObject element) { if (element is Visual || element is Visual3D) { for (int Index = 0; Index < VisualTreeHelper.GetChildrenCount(element); Index++) { DependencyObject Child = VisualTreeHelper.GetChild(element, Index); if (Child.ReadLocalValue(PersistentProperty.IdPathProperty) != DependencyProperty.UnsetValue) { //there is a Context registered. this means, the context path must be re-evaluated. //re-evaluation of children will be done in the called method PersistentProperty.ReEvaluateIdPath(Child); } else { //no context is specified here, so check the children PersistentProperty.NotifyChildrenThatIdPathChanged(Child); } } } }