/// <summary>
        /// Initializes a new instance of the <see cref="ViewToViewModelMappingContainer"/> class.
        /// </summary>
        /// <param name="dependencyObject">The dependency object.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="dependencyObject"/> is <c>null</c>.</exception>
        public ViewToViewModelMappingContainer(DependencyObject dependencyObject)
        {
            Argument.IsNotNull("dependencyObject", dependencyObject);

            var properties = dependencyObject.GetType().GetPropertiesEx();
            foreach (var property in properties)
            {
                object[] viewToViewModelAttributes = property.GetCustomAttributesEx(typeof(ViewToViewModelAttribute), false);
                if (viewToViewModelAttributes.Length > 0)
                {
                    Log.Debug("Property '{0}' is decorated with the ViewToViewModelAttribute, creating a mapping", property.Name);

                    var viewToViewModelAttribute = (ViewToViewModelAttribute)viewToViewModelAttributes[0];

                    string propertyName = property.Name;
                    string viewModelPropertyName = (string.IsNullOrEmpty(viewToViewModelAttribute.ViewModelPropertyName)) ? propertyName : viewToViewModelAttribute.ViewModelPropertyName;

                    var mapping = new ViewToViewModelMapping(propertyName, viewModelPropertyName, viewToViewModelAttribute.MappingType);

                    // Store it (in 2 dictionaries for high-speed access)
                    _viewToViewModelMappings.Add(property.Name, mapping);
                    _viewModelToViewMappings.Add(viewModelPropertyName, mapping);
                }
            }
        }
        public static T GetParentOfType <T>(this System.Windows.DependencyObject element) where T : System.Windows.DependencyObject
        {
            Type type = typeof(T);

            if (element == null)
            {
                return(null);
            }

            System.Windows.DependencyObject parent = System.Windows.Media.VisualTreeHelper.GetParent(element);

            if (parent == null &&
                ((System.Windows.FrameworkElement)element).Parent is System.Windows.DependencyObject)
            {
                parent = ((System.Windows.FrameworkElement)element).Parent;
            }

            if (parent == null)
            {
                return(null);
            }
            else if (parent.GetType() == type ||
                     parent.GetType().IsSubclassOf(type))
            {
                return(parent as T);
            }

            return(GetParentOfType <T>(parent));
        }
		public PropertyMetadata GetMetadata(DependencyObject d)
		{
			var theType = d.GetType();
			if (metadataByType.ContainsKey (d.GetType()))
				return metadataByType[d.GetType()];
			return null;
		}
 public DependencyObject FindMainGrid(DependencyObject Node)
 {
     if (Node != null)
     {
         if (VisualTreeHelper.GetChildrenCount(Node) > 0)        //Node has Childrens
         {
             for (int i = 0; i < VisualTreeHelper.GetChildrenCount(Node); i++)
             {
                 if (Node.GetType().ToString().Equals("System.Windows.Controls.Grid"))
                 {
                     return Node;
                 }
                 else
                 {
                     return FindMainGrid(VisualTreeHelper.GetChild(Node, i));
                 }
             }
         }
         else
         {
             if (Node.GetType().ToString().Equals("System.Windows.Controls.Grid"))
             {
                 return Node;
             }
         }
     }
     return null;
 }
Exemple #5
0
 private static IReturnCommandBehavior ResolveCommandBehavior(DependencyObject ctrl)
 {
     IReturnCommandBehavior behavior;
     if (ctrl.GetType() == typeof(TextBox))
         behavior = new ReturnCommandBehavior((TextBox)ctrl);
     else if (ctrl.GetType() == typeof(PasswordBox))
         behavior = new pwReturnCommandBehavior((PasswordBox)ctrl);
     else
         behavior = null;
     return behavior;
 }
Exemple #6
0
        private static void OnEventChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
            if (e.OldValue != null) {
                var @event = d.GetType().GetEvent(((RoutedEvent)e.OldValue).Name);
                @event.RemoveEventHandler(d, Delegate.CreateDelegate(@event.EventHandlerType, HandlerMethod));
            }

            if (e.NewValue != null) {
                var @event = d.GetType().GetEvent(((RoutedEvent)e.NewValue).Name);
                @event.AddEventHandler(d, Delegate.CreateDelegate(@event.EventHandlerType, HandlerMethod));
            }
        }
        private void BuildupView(IComponentContext context, DependencyObject instance)
        {
            try
            {
                if (instance == null)
                    return;

                foreach (object c in LogicalTreeHelper.GetChildren(instance))
                {
                    var child = c as DependencyObject;
                    if (child == null)
                        continue;

                    BuildupView(context, child);
                }

                Type viewInterfaceType = instance.GetType().GetInterface(typeof (IView<>).FullName);
                if (viewInterfaceType == null)
                    return;

                PropertyInfo viewModelProperty = viewInterfaceType.GetProperty("ViewModel");
                Type viewModelType = viewInterfaceType.GetGenericArguments()[0];


                object viewModel = context.Resolve(viewModelType);
                viewModelProperty.SetValue(instance, viewModel, null);

                viewInterfaceType.GetMethod("ViewInitialized").Invoke(instance, null);
            }
            catch (Exception e)
            {
            }
        }
Exemple #8
0
        protected static void ImgToShowSourcePropertyChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d.GetType() == typeof(AGImage))
            {
                try
                {
                    AGImage ag = d as AGImage;

                    System.Drawing.Icon ic = (System.Drawing.Icon)LaserControl.Properties.Resources.ResourceManager.GetObject(e.NewValue.ToString());
                    System.Drawing.Bitmap bmp = ic.ToBitmap();
                    System.Drawing.Bitmap bmpD = MakeGrayscale3(bmp);

                    ag.ImgEnabled = BitmapToImageSource(bmp);
                    ag.ImgDisabled = BitmapToImageSource(bmpD);

                    ag.Source = ag.IsEnabled ? ag.ImgEnabled : ag.ImgDisabled;

                    ic.Dispose();
                }
                catch
                {
                    //Mache nichts
                }
            }
        }
        private static object CoerceMVVMHasError(DependencyObject d,Object baseValue)
        {
            bool ret=(bool)baseValue ;
            if (BindingOperations.IsDataBound(d,MVVMHasErrorProperty))
            {
                if (GetHasErrorDescriptor(d) == null)
                {
                    DependencyPropertyDescriptor desc=DependencyPropertyDescriptor.FromProperty(Validation.HasErrorProperty, d.GetType());
                    desc.AddValueChanged(d,OnHasErrorChanged);
                    SetHasErrorDescriptor(d, desc);
                    ret = Validation.GetHasError(d);
                }
            }
            else
            {
                if (GetHasErrorDescriptor(d) != null)
                {
                    DependencyPropertyDescriptor desc= GetHasErrorDescriptor(d);
                    desc.RemoveValueChanged(d, OnHasErrorChanged);
                    SetHasErrorDescriptor(d, null);
                }
            }

            return ret;
        }
Exemple #10
0
		public bool IsDescendantOf (DependencyObject ancestor)
		{
			if (!(ancestor is Visual /*|| ancestor is Visual3D*/))
				throw new ArgumentException (string.Format ("'{0}' is not a Visual or Visual3D", ancestor.GetType()));

			throw new NotImplementedException ();
		}
Exemple #11
0
		public bool IsAncestorOf (DependencyObject descendant)
		{
			if (!(descendant is Visual /*|| descendant is Visual3D*/))
				throw new ArgumentException (string.Format ("'{0}' is not a Visual or Visual3D", descendant.GetType()));

			throw new NotImplementedException ();
		}
Exemple #12
0
 private static void IsEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (d.GetType() == typeof(PasswordBox))
         SetEnabledForPasswordBox((PasswordBox)d, (bool)e.NewValue);
     else
         SetEnabledForTextBox((TextBox)d, (bool)e.NewValue);
 }
        /// <summary>
        /// Attaches an event to the first Parent of obj (which must be a 
        /// FrameworkElement) which declares a public method with the name 
        /// "handler" and arguments of types "types".
        /// 
        /// When that method is found, attacher is invoked with:
        /// - sender is "obj"
        /// - target is the Parent that declares the method
        /// - method is the method of Parent
        /// </summary>
        /// <param name="obj">the object to which to attach an event</param>
        /// <param name="handler">the name of the method to be found in some Parent of obj</param>
        /// <param name="attacher">indicates how to attach an event to the target</param>
        public static void AttachEventHandler(DependencyObject obj, string methodName, Type[] handlerTypes, EventAttacher attacher)
        {
            FrameworkElement element = obj as FrameworkElement;
            if (element == null)
                throw new ArgumentException("Can only attach events to FrameworkElement instances, not to '" + obj.GetType() + "'");

            element.Loaded += (sender, e) =>
            {
                DependencyObject parent = sender as DependencyObject;

                MethodInfo info = null;
                while (info == null)
                {
                    info = parent.GetType().GetMethod(methodName, handlerTypes);
                    if (info != null)
                    {
                        attacher(sender, parent, info);
                        return;
                    }

                    parent = (parent is FrameworkElement) ? ((FrameworkElement)parent).Parent : null;

                    if (parent == null)
                        throw new ArgumentException("Can't find handler '" + methodName + "' (maybe it's not public, or set in a ControlTemplate?)");
                }
            };
        }
Exemple #14
0
        public static void RemoveHandler(DependencyObject element, RoutedEvent routedEvent, Delegate handler)
        {
            if (element == null) { throw new ArgumentNullException("element"); }

            var uie = element as UIElement;
            if (uie != null)
            {
                uie.RemoveHandler(routedEvent, handler);
            }
            else
            {
                var ce = element as ContentElement;
                if (ce != null)
                {
                    ce.RemoveHandler(routedEvent, handler);
                }
                else
                {
                    var u3d = element as UIElement3D;
                    if (u3d != null)
                        u3d.RemoveHandler(routedEvent, handler);
                    else
                        throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid element {0}.", element.GetType()));
                }
            }
        }
        public static DependencyProperty GetDataGridColumnDependencyProperty(DisplayPropertyInfo property, DependencyObject depObject)
        {
            DependencyProperty dp = null;
            if (property.LogicalDependencyProperty == LogicalDependencyProperty.Default)
            {
                PropertyInfo dpPropertyInfo = depObject.GetType().GetProperty(property.DependencyPropertyName, BindingFlags.Static);
                dp = dpPropertyInfo.GetValue(null) as DependencyProperty;
            }
            else if (property.LogicalDependencyProperty == LogicalDependencyProperty.IsEnabled)
            {
                dp = DataGridColumn.IsReadOnlyProperty;
            }
            else if (property.LogicalDependencyProperty == LogicalDependencyProperty.IsVisible)
            {
                dp = DataGridColumn.VisibilityProperty;
            }
            else if (property.LogicalDependencyProperty == LogicalDependencyProperty.IsReadOnly)
            {
                dp = DataGridColumn.IsReadOnlyProperty;
            }

            if (dp == null)
            {
                LoggerFactory.GetLogger().Warn("The dependency property of property '{}' cannot be found.", property.PropertyName);
            }

            return dp;
        }
 private static bool ImplementsMouseWheelEvent(DependencyObject obj)
 {
   if (obj == null)
     return false;
   var objType = obj.GetType();
   return MouseWheelEventImplementorTypes.Any(t => t.IsAssignableFrom(objType));
 }
Exemple #17
0
 public static void RebindInactiveBindings(DependencyObject dependencyObject)
 {
     foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(dependencyObject.GetType()))
     {
         var dpd = DependencyPropertyDescriptor.FromProperty(property);
         if (dpd != null)
         {
             var binding = BindingOperations.GetBindingExpressionBase(dependencyObject, dpd.DependencyProperty);
             if (binding != null)
             {
                 //if (property.Name == "DataContext" || binding.HasError || binding.Status != BindingStatus.Active)
                 {
                     // Ensure that no pending calls are in the dispatcher queue
                     Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action) delegate
                     {
                         // Remove and add the binding to re-trigger the binding error
                         dependencyObject.ClearValue(dpd.DependencyProperty);
                         BindingOperations.SetBinding(dependencyObject, dpd.DependencyProperty,
                             binding.ParentBindingBase);
                     });
                 }
             }
         }
     }
 }
Exemple #18
0
        static void BackgroundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!InDesignMode)
                return;

            d.GetType().GetProperty("Background").SetValue(d, e.NewValue, null);
        }
        public static void CommandPropertyChangedCallback(DependencyObject depObj, DependencyPropertyChangedEventArgs args)
        {
            string onEvent = (string)depObj.GetValue(OnEventProperty);
              Debug.Assert(onEvent != null, "OnEvent must be set.");
              var eventInfo = depObj.GetType().GetEvent(onEvent);
              if (eventInfo != null)
              {
            var mInfo = typeof(EventToCommandExecuter).GetMethod("OnRoutedEvent", BindingFlags.NonPublic | BindingFlags.Static);
            eventInfo.GetAddMethod().Invoke(depObj, new object[] { Delegate.CreateDelegate(eventInfo.EventHandlerType, mInfo) });
              }
              else
              {
            Debug.Fail(string.Format("{0} is not found on object {1}", onEvent, depObj.GetType()));

              }
        }
        private void ProcessElement(DependencyObject element, TreeViewItem previousItem)
        { 
            // Create a TreeViewItem for the current element
            TreeViewItem item = new TreeViewItem();
            item.Header = element.GetType().Name;
            item.IsExpanded = true;

            // Check whether this item should be added to the root of the tree
            //(if it's the first item), or nested under another item.
            if (previousItem == null)
            {
                treeElements.Items.Add(item);
            }
            else
            {
                previousItem.Items.Add(item);
            }

            // Check if this element contains other elements
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
            {
                // Process each contained element recursively
                ProcessElement(VisualTreeHelper.GetChild(element, i), item);
            }
        }
		public static DependencyProperty GetDependencyProperty(string name, DependencyObject parent, bool caseSensitive = false)
		{
			const string prop = "Property";
			var propertyName = name;
			if (!propertyName.ToLower().EndsWith(prop.ToLower()))
			{
				propertyName += prop;
			}
			var fieldInfoArray = parent.GetType().GetFields();
			foreach (var fieldInfo in fieldInfoArray)
			{
				if (caseSensitive)
				{
					if (fieldInfo.Name != propertyName) continue;
					var dependencyPropertyField = (DependencyProperty)fieldInfo.GetValue(parent);
					return dependencyPropertyField;
				}
				else
				{
					if (!string.Equals(fieldInfo.Name, propertyName, StringComparison.CurrentCultureIgnoreCase)) continue;
					var dependencyPropertyField = (DependencyProperty)fieldInfo.GetValue(parent);
					return dependencyPropertyField;
				}
			}
			throw new Exception("FSR.Reflection.CannotFindDependencyProperty(parent, name, caseSensitive)");
		}
		private static void ClipChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!InDesignMode)
                return;

            d.GetType().GetProperty("Clip").SetValue(d, e.NewValue, null);
        }
 public DisposableEventWrapper(DependencyObject source, DependencyProperty property, EventHandler handler)
 {
     Source = source;
     Property = property;
     Handler = handler;
     DependencyPropertyDescriptor.FromProperty(Property, Source.GetType()).AddValueChanged(Source, Handler);
 }
        public static DependencyObject GetAncestorByType(DependencyObject element, Type type)
        {
            if (element == null) return null;

            if (element.GetType() == type) return element;

            return GetAncestorByType(System.Windows.Media.VisualTreeHelper.GetParent(element), type);
        }
 internal FrameworkObject(DependencyObject d, bool throwIfNeither)
     : this(d)
 {
     if (throwIfNeither && _fe == null && _fce == null)
     {
         object arg = (d != null) ? (object)d.GetType() : (object)"NULL";
         throw new InvalidOperationException(SR.Get(SRID.MustBeFrameworkDerived, arg));
     }
 }
 private static bool RemoveChild(DependencyObject parent, UIElement child)
 {
     if (parent.GetType().IsA(typeof(Decorator)))
     {
         ((Decorator)parent).Child = null;
         return true;
     }
     return false;
 }
Exemple #27
0
        void BuildVisualTree(int depth, DependencyObject obj)
        {
            // Add the type name to the dataToShow member variable.
            dataToShow += new string(' ', depth) + obj.GetType().Name + "\n";

            // Make a recursive call for each visual child
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
                BuildVisualTree(depth + 1, VisualTreeHelper.GetChild(obj, i));
        }
 private DelayedRegionCreationBehavior GetBehavior(DependencyObject control, MockRegionManagerAccessor accessor, MockRegionAdapter adapter)
 {
     var mappings = new RegionAdapterMappings();
     mappings.RegisterMapping(control.GetType(), adapter);
     var behavior = new DelayedRegionCreationBehavior(mappings);
     behavior.RegionManagerAccessor = accessor;
     behavior.TargetElement = control;
     return behavior;
 }
 private static void AutoWireViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (DesignerProperties.GetIsInDesignMode(d)) return;
     var viewType = d.GetType();
     var viewTypeName = viewType.FullName;
     var viewModelTypeName = viewTypeName + "Model";
     var viewModelType = Type.GetType(viewModelTypeName);
     var viewModel = Activator.CreateInstance(viewModelType);
     ((FrameworkElement)d).DataContext = viewModel;
 }
Exemple #30
0
        /// <summary>
        ///     Creates and attaches new region to the specified <paramref name="view"/>
        /// </summary>
        /// <param name="view">View to create new region for</param>
        /// <returns>Initialized and attached <see cref="IRegion"/> object</returns>
        /// <exception cref="InvalidOperationException">When a new region cannot be instantiated, beause view's type is not supported by this factory</exception>
        /// <exception cref="ArgumentNullException">When <paramref name="view"/> is null</exception>
        public IRegion CreateRegion(DependencyObject view)
        {
            if (view == null) throw new ArgumentNullException("view");

            var adapter = FindAdapterFor(view);
            if (adapter == null)
                throw new InvalidOperationException("No adapter has been found for view of type " +
                                                    view.GetType().Name);

            return adapter.AdaptView(view);
        }
Exemple #31
0
        private static IList<DependencyProperty> GetAttachedProperties(DependencyObject obj) {
            List<DependencyProperty> result = new List<DependencyProperty>();

            foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(obj.GetType())) {
                var dpd = DependencyPropertyDescriptor.FromProperty(pd);
                if (dpd != null) {
                    result.Add(dpd.DependencyProperty);
                }
            }
            return result;
        }
Exemple #32
0
 internal static void RemoveHandler(DependencyObject d, RoutedEvent routedEvent, Delegate handler)
 {
     if (d is UIElement)
     {
         ((UIElement)d).RemoveHandler(routedEvent, handler);
     }
     else if (d is ContentElement)
     {
         ((ContentElement)d).RemoveHandler(routedEvent, handler);
     }
     else if (d is IInputElement)
     {
         ((IInputElement)d).RemoveHandler(routedEvent, handler);
     }
     else
     {
         throw new ArgumentException(String.Format("type '{0}' is not subclass of UIElement or ContentElement, and doesn't implement the IInputElement interface, so you can't add RoutedEvent handlers to it.", d.GetType()));
     }
 }
        public IExpression CreateExpression(DependencyObject dependencyObject, DependencyProperty dependencyProperty)
        {
            IResourceContainer resourceContainer = dependencyObject as IResourceContainer;

            if (resourceContainer == null)
            {
                throw new Granular.Exception("ResourceReferenceExpression cannot be attached to \"{0}\" as it does not implement \"{1}\"", dependencyObject.GetType().Name, typeof(IResourceContainer).Name);
            }

            return(new ResourceReferenceExpression(resourceContainer, resourceKey));
        }
        // Token: 0x06000691 RID: 1681 RVA: 0x00014908 File Offset: 0x00012B08
        internal DependencyObject InstantiateTree(UncommonField <HybridDictionary[]> dataField, DependencyObject container, DependencyObject parent, List <DependencyObject> affectedChildren, ref List <DependencyObject> noChildIndexChildren, ref FrugalStructList <ChildPropertyDependent> resourceDependents)
        {
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseFefCrInstBegin);
            FrameworkElement frameworkElement = container as FrameworkElement;
            bool             flag             = frameworkElement != null;
            DependencyObject dependencyObject = null;

            if (this._text != null)
            {
                IAddChild addChild = parent as IAddChild;
                if (addChild == null)
                {
                    throw new InvalidOperationException(SR.Get("TypeMustImplementIAddChild", new object[]
                    {
                        parent.GetType().Name
                    }));
                }
                addChild.AddText(this._text);
            }
            else
            {
                dependencyObject = this.CreateDependencyObject();
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseFefCrInstEnd);
                FrameworkObject frameworkObject = new FrameworkObject(dependencyObject);
                Visual3D        visual3D        = null;
                bool            flag2           = false;
                if (!frameworkObject.IsValid)
                {
                    visual3D = (dependencyObject as Visual3D);
                    if (visual3D != null)
                    {
                        flag2 = true;
                    }
                }
                bool isFE = frameworkObject.IsFE;
                if (!flag2)
                {
                    FrameworkElementFactory.NewNodeBeginInit(isFE, frameworkObject.FE, frameworkObject.FCE);
                    if (StyleHelper.HasResourceDependentsForChild(this._childIndex, ref resourceDependents))
                    {
                        frameworkObject.HasResourceReference = true;
                    }
                    FrameworkElementFactory.UpdateChildChains(this._childName, this._childIndex, isFE, frameworkObject.FE, frameworkObject.FCE, affectedChildren, ref noChildIndexChildren);
                    FrameworkElementFactory.NewNodeStyledParentProperty(container, flag, isFE, frameworkObject.FE, frameworkObject.FCE);
                    if (this._childIndex != -1)
                    {
                        StyleHelper.CreateInstanceDataForChild(dataField, container, dependencyObject, this._childIndex, this._frameworkTemplate.HasInstanceValues, ref this._frameworkTemplate.ChildRecordFromChildIndex);
                    }
                    if (this.HasLoadedChangeHandler)
                    {
                        BroadcastEventHelper.AddHasLoadedChangeHandlerFlagInAncestry(dependencyObject);
                    }
                }
                else if (this._childName != null)
                {
                    affectedChildren.Add(dependencyObject);
                }
                else
                {
                    if (noChildIndexChildren == null)
                    {
                        noChildIndexChildren = new List <DependencyObject>(4);
                    }
                    noChildIndexChildren.Add(dependencyObject);
                }
                if (container == parent)
                {
                    TemplateNameScope value = new TemplateNameScope(container);
                    NameScope.SetNameScope(dependencyObject, value);
                    if (flag)
                    {
                        frameworkElement.TemplateChild = frameworkObject.FE;
                    }
                    else
                    {
                        FrameworkElementFactory.AddNodeToLogicalTree((FrameworkContentElement)parent, this._type, isFE, frameworkObject.FE, frameworkObject.FCE);
                    }
                }
                else
                {
                    this.AddNodeToParent(parent, frameworkObject);
                }
                if (!flag2)
                {
                    StyleHelper.InvalidatePropertiesOnTemplateNode(container, frameworkObject, this._childIndex, ref this._frameworkTemplate.ChildRecordFromChildIndex, false, this);
                }
                else
                {
                    for (int i = 0; i < this.PropertyValues.Count; i++)
                    {
                        if (this.PropertyValues[i].ValueType != PropertyValueType.Set)
                        {
                            throw new NotSupportedException(SR.Get("Template3DValueOnly", new object[]
                            {
                                this.PropertyValues[i].Property
                            }));
                        }
                        object    obj       = this.PropertyValues[i].ValueInternal;
                        Freezable freezable = obj as Freezable;
                        if (freezable != null && !freezable.CanFreeze)
                        {
                            obj = freezable.Clone();
                        }
                        MarkupExtension markupExtension = obj as MarkupExtension;
                        if (markupExtension != null)
                        {
                            ProvideValueServiceProvider provideValueServiceProvider = new ProvideValueServiceProvider();
                            provideValueServiceProvider.SetData(visual3D, this.PropertyValues[i].Property);
                            obj = markupExtension.ProvideValue(provideValueServiceProvider);
                        }
                        visual3D.SetValue(this.PropertyValues[i].Property, obj);
                    }
                }
                for (FrameworkElementFactory frameworkElementFactory = this._firstChild; frameworkElementFactory != null; frameworkElementFactory = frameworkElementFactory._nextSibling)
                {
                    frameworkElementFactory.InstantiateTree(dataField, container, dependencyObject, affectedChildren, ref noChildIndexChildren, ref resourceDependents);
                }
                if (!flag2)
                {
                    FrameworkElementFactory.NewNodeEndInit(isFE, frameworkObject.FE, frameworkObject.FCE);
                }
            }
            return(dependencyObject);
        }
        /// <summary>
        /// Gets an observable sequence of property change notifications for the specified <see cref="DependencyProperty"/>,
        /// raised by the specified <see cref="DependencyObject"/>.
        /// </summary>
        /// <typeparam name="TValue">Type of the value represented by the <see cref="DependencyProperty"/>.</typeparam>
        /// <param name="obj">The <see cref="DependencyObject"/> that defines the specified <paramref name="property"/>.</param>
        /// <param name="property">The <see cref="DependencyProperty"/> that raises change notifications for the specified object.</param>
        /// <returns>An observable sequence of property change notifications for the specified <see cref="DependencyProperty"/>,
        /// raised by the specified <see cref="DependencyObject"/>.</returns>
        public static IObservable <TValue> DependencyPropertyChanged <TValue>(
            this DependencyObject obj,
            DependencyProperty property)
        {
            Contract.Requires(obj != null);
            Contract.Requires(property != null);
            Contract.Ensures(Contract.Result <IObservable <TValue> >() != null);

            var propertyDescriptor = DependencyPropertyDescriptor.FromProperty(property, obj.GetType());

            if (propertyDescriptor == null)
            {
                throw new ArgumentException(Errors.DependencyPropertyNotFound, "property");
            }

            return(propertyDescriptor.PropertyChanged(obj).Select(_ => (TValue)obj.GetValue(property)));
        }