Exemple #1
0
 /// <summary>
 /// Creates a default ToolTip element
 /// </summary>
 public ToolTip()
 {
     DefaultStyleKey      = typeof(ToolTip);
     propagateDataContext = delegate {
         if (_parentPopup != null && TooltipParent != null)
         {
             _parentPopup.DataContext = TooltipParent.DataContext;
         }
     };
 }
Exemple #2
0
        internal void AddPropertyChangedHandler(DependencyProperty property, UnmanagedPropertyChangeHandler handler)
        {
            // Store the delegate in managed land to prevent it being GC'ed early
            if (propertyChangedHandlers == null)
            {
                propertyChangedHandlers = new List <KeyValuePair <int, UnmanagedPropertyChangeHandler> > ();
            }

            int token = NativeMethods.dependency_object_add_managed_property_change_handler(native, property.Native, invoke_property_change_handler_cb, IntPtr.Zero);

            propertyChangedHandlers.Add(new KeyValuePair <int, UnmanagedPropertyChangeHandler> (token, handler));
        }
Exemple #3
0
        internal override void OnDetached(DependencyObject element)
        {
            if (!Attached)
            {
                return;
            }

            base.OnDetached(element);
            if (TwoWayTextBoxText)
            {
                ((TextBox)Target).LostFocus -= TextBoxLostFocus;
            }

            var targetFE = element as FrameworkElement;

            if (IsMentorDataContextBound)
            {
                Target.MentorChanged -= MentorChanged;
                SetDataContextSource(null);
            }
            else if (IsParentDataContextBound)
            {
                targetFE.VisualParentChanged -= ParentChanged;
                SetDataContextSource(null);
            }
            else if (IsSelfDataContextBound)
            {
                SetDataContextSource(null);
            }

            targetFE = targetFE ?? Target.Mentor;
            if (targetFE != null && CurrentError != null)
            {
                Validation.RemoveError(targetFE, CurrentError);
                CurrentError = null;
            }

            if (updateDataSourceCallback != null)
            {
                Target.RemovePropertyChangedHandler(Property, updateDataSourceCallback);
                updateDataSourceCallback = null;
            }

            PropertyPathWalker.Update(null);
        }
Exemple #4
0
        internal void RemovePropertyChangedHandler(DependencyProperty property, UnmanagedPropertyChangeHandler handler)
        {
            if (propertyChangedHandlers == null)
            {
                return;
            }

            // When removing a delegate from native, we have to ensure we pass the exact same object reference
            // to native code, otherwise the native pointer will be different and we'll fail to remove it from
            // the native list. To enforce this, use the delegate in the List when invoking the native code.
            for (int i = 0; i < propertyChangedHandlers.Count; i++)
            {
                if (propertyChangedHandlers [i].Value == handler)
                {
                    NativeMethods.dependency_object_remove_property_change_handler(native, propertyChangedHandlers [i].Key);
                    propertyChangedHandlers.RemoveAt(i);
                    break;
                }
            }
        }
Exemple #5
0
        internal override void OnAttached(DependencyObject element)
        {
            if (Attached)
            {
                return;
            }

            base.OnAttached(element);
            CalculateDataSource();

            if (TwoWayTextBoxText)
            {
                ((TextBox)Target).LostFocus += TextBoxLostFocus;
            }

            var targetFE = element as FrameworkElement;

            if (Binding.Mode == BindingMode.TwoWay && Property is CustomDependencyProperty)
            {
                updateDataSourceCallback = delegate {
                    try {
                        if (!Updating)
                        {
                            TryUpdateSourceObject(Target.GetValue(Property));
                        }
                    } catch (Exception ex) {
                        try {
                            Console.WriteLine("Moonlight: Unhandled exception in BindingExpressionBase.OnAttached's updateDataSourceCallback: {0}", ex);
                        } catch {
                            // Ignore
                        }
                    }
                };
                Target.AddPropertyChangedHandler(Property, updateDataSourceCallback);
            }
        }
Exemple #6
0
		internal override void OnDetached (DependencyObject element)
		{
			if (!Attached)
				return;

			base.OnDetached (element);
			if (TwoWayTextBoxText)
				((TextBox) Target).LostFocus -= TextBoxLostFocus;

			var targetFE = element as FrameworkElement;
			if (IsMentorDataContextBound) {
				Target.MentorChanged -= MentorChanged;
				SetDataContextSource (null);
			} else if (IsParentDataContextBound) {
				targetFE.VisualParentChanged -= ParentChanged;
				SetDataContextSource (null);
			} else if (IsSelfDataContextBound) {
				SetDataContextSource (null);
			}

			targetFE = targetFE ?? Target.Mentor;
			if (targetFE != null && CurrentError != null) {
				Validation.RemoveError (targetFE, CurrentError);
				CurrentError = null;
			}

			if (updateDataSourceCallback != null) {
				Target.RemovePropertyChangedHandler (Property, updateDataSourceCallback);
				updateDataSourceCallback = null;
			}

			PropertyPathWalker.Update (null);
		}
Exemple #7
0
		internal override void OnAttached (DependencyObject element)
		{
			if (Attached)
				return;

			base.OnAttached (element);
			CalculateDataSource ();

			if (TwoWayTextBoxText)
				((TextBox) Target).LostFocus += TextBoxLostFocus;

			var targetFE = element as FrameworkElement;
			if (Binding.Mode == BindingMode.TwoWay && Property is CustomDependencyProperty) {
				updateDataSourceCallback = delegate {
					try {
						if (!Updating)
							TryUpdateSourceObject (Target.GetValue (Property));
					} catch (Exception ex) {
						try {
							Console.WriteLine ("Moonlight: Unhandled exception in BindingExpressionBase.OnAttached's updateDataSourceCallback: {0}", ex);
						} catch {
							// Ignore
						}
					}
				};
				Target.AddPropertyChangedHandler (Property, updateDataSourceCallback);
			}
		}
Exemple #8
0
		internal override void OnAttached (DependencyObject element)
		{
			base.OnAttached (element);
			if (TwoWayTextBoxText)
				((TextBox) Target).LostFocus += TextBoxLostFocus;

			if (IsMentorBound) {
				Target.MentorChanged += MentorChanged;
				mentor = Target.Mentor;
				AttachDataContextHandlers (mentor);
			}

			if (Binding.Mode == BindingMode.TwoWay && Property is CustomDependencyProperty) {
				updateDataSourceCallback = delegate {
					try {
						if (!Updating)
							TryUpdateSourceObject (Target.GetValue (Property));
					} catch (Exception ex) {
						try {
							Console.WriteLine ("Moonlight: Unhandled exception in BindingExpressionBase.OnAttached's updateDataSourceCallback: {0}", ex);
						} catch {
							// Ignore
						}
					}
				};
				NativeMethods.dependency_object_add_property_change_handler (Target.native, Property.Native, updateDataSourceCallback, IntPtr.Zero);
			}
		}
Exemple #9
0
		internal BindingExpressionBase (Binding binding, DependencyObject target, DependencyProperty property)
		{
			Binding = binding;
			Target = target;
			Property = property;

			mentorDataContextChangedCallback = OnNativeMentorDataContextChangedSafe;

			bool bindsToView = property == FrameworkElement.DataContextProperty || property.PropertyType == typeof (IEnumerable) || property.PropertyType == typeof (ICollectionView);
			PropertyPathWalker = new PropertyPathWalker (Binding.Path.Path, binding.BindsDirectlyToSource, bindsToView);
			if (Binding.Mode != BindingMode.OneTime)
				PropertyPathWalker.ValueChanged += PropertyPathValueChanged;
		}
Exemple #10
0
		internal override void OnDetached (DependencyObject element)
		{
			if (!Attached)
				return;

			base.OnDetached (element);
			if (TwoWayTextBoxText)
				((TextBox) Target).LostFocus -= TextBoxLostFocus;

			if (IsMentorBound) {
				DetachDataContextHandlers (mentor);
				mentor = null;
				Target.MentorChanged -= MentorChanged;;
			}

			if (updateDataSourceCallback != null) {
				NativeMethods.dependency_object_remove_property_change_handler (Target.native, Property.Native, updateDataSourceCallback);
				updateDataSourceCallback = null;
			}

			PropertyPathWalker.Update (null);
		}
Exemple #11
0
 public CollectionViewNode(bool bindsDirectlyToSource, bool bindToView)
 {
     BindsDirectlyToSource = bindsDirectlyToSource;
     BindToView            = bindToView;
     ViewChangedHandler    = ViewChanged;
 }
Exemple #12
0
        private static DependencyProperty RegisterAny(string name, Type propertyType, Type ownerType, PropertyMetadata metadata, bool attached, bool readOnly, bool setsParent, bool custom)
        {
            ManagedType property_type;
            ManagedType owner_type;
            UnmanagedPropertyChangeHandler handler = null;
            CustomDependencyProperty       result;
            bool   is_nullable   = false;
            object default_value = DependencyProperty.UnsetValue;
            PropertyChangedCallback property_changed_callback = null;

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (name.Length == 0)
            {
                throw new ArgumentException("The 'name' argument cannot be an empty string");
            }

            if (propertyType == null)
            {
                throw new ArgumentNullException("propertyType");
            }

            if (ownerType == null)
            {
                throw new ArgumentNullException("ownerType");
            }

            if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                is_nullable = true;
                // Console.WriteLine ("DependencyProperty.RegisterAny (): found nullable {0}, got nullable {1}", propertyType.FullName, propertyType.GetGenericArguments () [0].FullName);
                propertyType = propertyType.GetGenericArguments() [0];
            }

            Types types = Deployment.Current.Types;

            property_type = types.Find(propertyType);
            owner_type    = types.Find(ownerType);

            if (metadata != null)
            {
                default_value             = metadata.DefaultValue ?? UnsetValue;
                property_changed_callback = metadata.property_changed_callback;
            }

            if ((default_value == DependencyProperty.UnsetValue) && propertyType.IsValueType && !is_nullable)
            {
                default_value = Activator.CreateInstance(propertyType);
            }

            if (default_value != null && default_value != UnsetValue && !propertyType.IsAssignableFrom(default_value.GetType()))
            {
                throw new ArgumentException(string.Format("DefaultValue is of type {0} which is not compatible with type {1}", default_value.GetType(), propertyType));
            }

            if (property_changed_callback != null)
            {
                handler = UnmanagedPropertyChangedCallbackSafe;
            }

            Value v;

            if (default_value == DependencyProperty.UnsetValue)
            {
                v = new Value {
                    Kind = types.TypeToKind(propertyType), IsNull = true
                };
                default_value = null;
            }
            else
            {
                v = Value.FromObject(default_value, true);
            }

            IntPtr handle;

            using (v) {
                var val = v;
                if (custom)
                {
                    handle = NativeMethods.dependency_property_register_custom_property(name, property_type.native_handle, owner_type.native_handle, ref val, attached, readOnly, handler);
                }
                else
                {
                    handle = NativeMethods.dependency_property_register_core_property(name, property_type.native_handle, owner_type.native_handle, ref val, attached, readOnly, handler);
                }
            }

            if (handle == IntPtr.Zero)
            {
                return(null);
            }

            if (is_nullable)
            {
                NativeMethods.dependency_property_set_is_nullable(handle, true);
            }

            result          = new CustomDependencyProperty(handle, name, property_type, owner_type, default_value);
            result.attached = attached;
            result.PropertyChangedHandler    = handler;
            result.property_changed_callback = property_changed_callback;

            return(result);
        }
		internal override void OnAttached (DependencyObject element)
		{
			base.OnAttached (element);

			Target = (FrameworkElement) element;
			if (change_handler == null)
				change_handler = new UnmanagedPropertyChangeHandler (PropertyChanged);

			ContentControl c = Target as ContentControl;
			if (TargetProperty == ContentControl.ContentProperty && c != null) {
				SetsParent = c.ContentSetsParent;
				c.ContentSetsParent = false;
			}

			// Note that Target.TemplateOwner is a weak reference - it can be GC'ed at any time
			var source = Target.TemplateOwner;
			if (source != null)
				NativeMethods.dependency_object_add_property_change_handler (source.native, SourceProperty.Native, change_handler, IntPtr.Zero);
		}
Exemple #14
0
		internal void AddPropertyChangedHandler (DependencyProperty property, UnmanagedPropertyChangeHandler handler)
		{
			// Store the delegate in managed land to prevent it being GC'ed early
			if (propertyChangedHandlers == null)
				propertyChangedHandlers = new List<UnmanagedPropertyChangeHandler> ();

			propertyChangedHandlers.Add (handler);
			NativeMethods.dependency_object_add_property_change_handler (native, property.Native, handler, IntPtr.Zero);
		}
Exemple #15
0
		internal void AddPropertyChangedHandler (DependencyProperty property, UnmanagedPropertyChangeHandler handler)
		{
			// Store the delegate in managed land to prevent it being GC'ed early
			if (propertyChangedHandlers == null)
				propertyChangedHandlers = new List<KeyValuePair<int, UnmanagedPropertyChangeHandler>> ();

			int token = NativeMethods.dependency_object_add_managed_property_change_handler (native, property.Native, invoke_property_change_handler_cb, IntPtr.Zero);
			propertyChangedHandlers.Add (new KeyValuePair <int, UnmanagedPropertyChangeHandler> (token, handler));
		}
Exemple #16
0
		internal void RemovePropertyChangedHandler (DependencyProperty property, UnmanagedPropertyChangeHandler handler)
		{
			if (propertyChangedHandlers == null)
				return;

			// When removing a delegate from native, we have to ensure we pass the exact same object reference
			// to native code, otherwise the native pointer will be different and we'll fail to remove it from
			// the native list. To enforce this, use the delegate in the List when invoking the native code.
			int index = propertyChangedHandlers.IndexOf (handler);
			if (index != -1) {
				NativeMethods.dependency_object_remove_property_change_handler (native, property.Native, propertyChangedHandlers [index]);
				propertyChangedHandlers.RemoveAt (index);
			}
		}
Exemple #17
0
		internal void RemovePropertyChangedHandler (DependencyProperty property, UnmanagedPropertyChangeHandler handler)
		{
			if (propertyChangedHandlers == null)
				return;

			// When removing a delegate from native, we have to ensure we pass the exact same object reference
			// to native code, otherwise the native pointer will be different and we'll fail to remove it from
			// the native list. To enforce this, use the delegate in the List when invoking the native code.
			for (int i = 0; i < propertyChangedHandlers.Count; i++) {
				if (propertyChangedHandlers [i].Value == handler) {
					NativeMethods.dependency_object_remove_property_change_handler (native, propertyChangedHandlers [i].Key);
					propertyChangedHandlers.RemoveAt (i);
					break;
				}
			}
		}
Exemple #18
0
		public CollectionViewNode (bool bindsDirectlyToSource, bool bindToView)
		{
			BindsDirectlyToSource = bindsDirectlyToSource;
			BindToView = bindToView;
			ViewChangedHandler = ViewChanged;
		}
Exemple #19
0
 /// <summary> 
 /// Creates a default ToolTip element
 /// </summary>
 public ToolTip()
 { 
     DefaultStyleKey = typeof (ToolTip);
     propagateDataContext = delegate {
         if (_parentPopup != null && TooltipParent != null)
         _parentPopup.DataContext = TooltipParent.DataContext;
     };
 }