static void OnNameScopeSourceChanged(
            DependencyObject depObj,
            DependencyPropertyChangedEventArgs e)
        {
            ElementSpy spy = e.NewValue as ElementSpy;

            if (spy == null || spy.Element == null)
            {
                return;
            }

            INameScope scope =
                NameScope.GetNameScope(spy.Element);

            if (scope == null)
            {
                return;
            }

            depObj.Dispatcher.BeginInvoke(
                DispatcherPriority.Normal,
                (Action) delegate
            {
                NameScope.SetNameScope(depObj, scope);
            });
        }
 public static void SetNameScopeSource(
     DependencyObject obj, ElementSpy value)
 {
     obj.SetValue(NameScopeSourceProperty, value);
 }