예제 #1
0
        public void GetProperties_SetValueOutOfRangeWithHandler_CallsValueChanged()
        {
            var array                   = new int[] { 1, 2, 3 };
            var smallerArray            = new int[] { 1, 2 };
            PropertyDescriptor property = Converter.GetProperties(array)[2];
            int          callCount      = 0;
            EventHandler handler        = (sender, e) =>
            {
                Assert.Same(smallerArray, sender);
                Assert.Same(EventArgs.Empty, e);
                callCount++;
            };

            // With handler.
            property.AddValueChanged(smallerArray, handler);
            property.SetValue(smallerArray, 0);
            Assert.Equal(new int[] { 1, 2 }, smallerArray);
            Assert.Equal(new int[] { 1, 2, 3 }, array);
            Assert.Equal(1, callCount);

            // Remove handler.
            property.RemoveValueChanged(smallerArray, handler);
            property.SetValue(smallerArray, 1);
            Assert.Equal(new int[] { 1, 2 }, smallerArray);
            Assert.Equal(new int[] { 1, 2, 3 }, array);
            Assert.Equal(1, callCount);
        }
예제 #2
0
        private static void OnCustomSortCommandChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            // We only setup sorting for datagrids
            DataGrid dg = obj as DataGrid;

            if (dg == null)
            {
                return;
            }

            // Add an event handler for the sort event
            dg.Sorting += DataGridSorting;

            // Get the sort command
            ICommand command = GetCustomSortCommand(dg);

            foreach (var col in dg.Columns)
            {
                // Add an event handler to the SortDirection property
                PropertyDescriptor prop = TypeDescriptor.GetProperties(col)["SortDirection"];
                prop.AddValueChanged(col, SortDirectionChanged);

                // Add the CustomSortCommand to the columns also
                DataGridAttachedProperties.SetCustomSortCommand(col, command);
            }
        }
예제 #3
0
        /// <param name="designer"> The property designer. </param>
        public PropertyDesignerManager(object instance, PropertyDescriptor descriptor, IDesigner designer)
        {
            _designer           = designer;
            _designer.Disposed += new EventHandler(DesignerDisposed);
            _designer.Service.OnRequestSave += new RequestHandler(DesignerRequestedSave);

            _descriptor = descriptor;
            _descriptor.AddValueChanged(instance, new EventHandler(PropertyChanged));

            _instance = instance;
            IDisposableNotify localInstance = _instance as IDisposableNotify;

            if (localInstance != null)
            {
                localInstance.Disposed += new EventHandler(InstanceDisposed);
            }

            ISite site = ((IComponent)_instance).Site;

            if (site != null)
            {
                _service = (IDesignService)site.GetService(typeof(IDesignService));
                _service.Dependants.Add(_designer.Service);
            }
            else
            {
                _service = null;
            }
        }
예제 #4
0
        /// <summary>
        /// This is used to connect and disconnect the property changed event handlers
        /// </summary>
        /// <param name="connect">True to connect, false to disconnect</param>
        internal void WirePropChangedEvents(bool connect)
        {
            PropertyDescriptor propInfo = null;
            FieldInfo          fi;

            if (rowSource != null)
            {
                BindingsCollection bc = this.BindingContext[rowSource].Bindings;

                // The bindings don't expose an event or anything else that notifies us when a bound field
                // changes.  As such, we have to hack into the mechanism using Reflection.
                foreach (Binding b in bc)
                {
                    fi = b.GetType().GetField("propInfo", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (fi != null)
                    {
                        propInfo = (PropertyDescriptor)fi.GetValue(b);
                    }

                    if (propInfo != null)
                    {
                        if (connect)
                        {
                            propInfo.AddValueChanged(b.Control, Target_PropertyChanged);
                        }
                        else
                        {
                            propInfo.RemoveValueChanged(b.Control, Target_PropertyChanged);
                        }
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyItem"/> class.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="component">The component property belongs to.</param>
        /// <param name="descriptor">The property descriptor</param>
        public PropertyItem(PropertyGrid owner, object component, PropertyDescriptor descriptor)
            : this(null)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }

            Owner       = owner;
            Name        = descriptor.Name;
            _component  = component;
            _descriptor = descriptor;

            IsBrowsable    = descriptor.IsBrowsable;
            _isReadOnly    = descriptor.IsReadOnly;
            _description   = descriptor.Description;
            _categoryName  = descriptor.Category;
            _isLocalizable = descriptor.IsLocalizable;

            _metadata = new AttributesContainer(descriptor.Attributes);
            _descriptor.AddValueChanged(component, ComponentValueChanged);
        }
예제 #6
0
 private EventMonitor(object instance, PropertyDescriptor property)
 {
     property.AddValueChanged(instance, (sender, e) =>
     {
         count++;
     });
 }
예제 #7
0
        private static void OnScrollOnNewItemChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            ListBox listBox = dependencyObject as ListBox;

            if (listBox != null)
            {
                Boolean oldValue = (Boolean)e.OldValue;
                Boolean newValue = (Boolean)e.NewValue;

                if (newValue != oldValue)
                {
                    PropertyDescriptor itemsSourcePropertyDescriptor = TypeDescriptor.GetProperties(listBox)["ItemsSource"];

                    if (newValue)
                    {
                        listBox.Loaded   += ListBox_Loaded;
                        listBox.Unloaded += ListBox_Unloaded;

                        itemsSourcePropertyDescriptor.AddValueChanged(listBox, ListBox_ItemsSourceChanged);
                    }
                    else
                    {
                        listBox.Loaded   -= ListBox_Loaded;
                        listBox.Unloaded -= ListBox_Unloaded;

                        if (ListBoxBehaviors.Associations.ContainsKey(listBox))
                        {
                            ListBoxBehaviors.Associations[listBox].Dispose();
                        }

                        itemsSourcePropertyDescriptor.RemoveValueChanged(listBox, ListBox_ItemsSourceChanged);
                    }
                }
            }
        }
예제 #8
0
        public void AddValueChanged_WhenPropertyChanges_CallbackIsInvoked()
        {
            int    callbackInvocationCount = 0;
            object actualSender            = null;
            string actualValueInCallback   = null;

            EventHandler callback = (s, _) => {
                callbackInvocationCount++;
                actualSender          = s;
                actualValueInCallback = _viewModel.CommentTestAccessor;
            };

            PropertyDescriptor pd = GetPropertyDescriptor("Comment");

            pd.AddValueChanged(_viewModel, callback);

            var newPropertyValue = ArbitraryCommentValue;

            _viewModel.CommentTestAccessor = newPropertyValue;

            Assert.AreNotEqual(0, callbackInvocationCount, "The callback was not invoked.");
            Assert.AreEqual(1, callbackInvocationCount, "The callback should not be invoked more than once.");
            Assert.AreSame(_viewModel, actualSender, "The sender of the event handler should be the view model.");
            Assert.AreEqual(newPropertyValue, actualValueInCallback, "GetValue should already return the new property value in the callback.");
        }
예제 #9
0
        internal void InitSummaryTable(Label title, DataGrid dataGrid, ComboBox columns)
        {
            TheDataGrid        = dataGrid;
            TheSelectedColumns = columns;
            TheTitle           = title;

            if (title != null)
            {
                TheTitle.Content = DEFAULT_TABLE_LABEL;
            }

            if (TheDataGrid != null)
            {
                TheDataGrid.Sorting += DataGrid_Sorting; // sort numbers descending

                PropertyDescriptor orderPd = DependencyPropertyDescriptor.FromProperty(DataGridColumn.DisplayIndexProperty, typeof(DataGridColumn));
                foreach (var column in dataGrid.Columns)
                {
                    orderPd.AddValueChanged(column, new EventHandler(ColumnDisplayIndexPropertyChanged));
                }

                if (TheSelectedColumns != null)
                {
                    TheShownColumns = DataGridUtil.LoadColumns(TheSelectedColumns, TheDataGrid);
                }
            }
        }
예제 #10
0
        public static void OnScrollOnNewItemChanged(
            DependencyObject d,
            DependencyPropertyChangedEventArgs e)
        {
            ListBox listBox = d as ListBox;

            if (listBox == null)
            {
                return;
            }
            bool oldValue = (bool)e.OldValue, newValue = (bool)e.NewValue;

            if (newValue == oldValue)
            {
                return;
            }
            if (newValue)
            {
                listBox.Loaded   += ListBox_Loaded;
                listBox.Unloaded += ListBox_Unloaded;
                PropertyDescriptor itemsSourcePropertyDescriptor = TypeDescriptor.GetProperties(listBox)["ItemsSource"];
                itemsSourcePropertyDescriptor.AddValueChanged(listBox, ListBox_ItemsSourceChanged);
            }
            else
            {
                listBox.Loaded   -= ListBox_Loaded;
                listBox.Unloaded -= ListBox_Unloaded;
                if (Associations.ContainsKey(listBox))
                {
                    Associations[listBox].Dispose();
                }
                PropertyDescriptor itemsSourcePropertyDescriptor = TypeDescriptor.GetProperties(listBox)["ItemsSource"];
                itemsSourcePropertyDescriptor.RemoveValueChanged(listBox, ListBox_ItemsSourceChanged);
            }
        }
예제 #11
0
        public ComponentChangeDispatcher(IServiceProvider serviceProvider, object component, PropertyDescriptor propertyDescriptor)
        {
            this.serviceProvider = serviceProvider;
            this.component       = component;
            this.property        = propertyDescriptor;

            IComponentChangeService changeService = serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (changeService != null)
            {
                try
                {
                    newValue = oldValue = propertyDescriptor.GetValue(component);
                    propertyDescriptor.AddValueChanged(component, new EventHandler(OnValueChanged));
                    changeService.OnComponentChanging(component, propertyDescriptor);
                }
                catch (CheckoutException coEx)
                {
                    if (coEx == CheckoutException.Canceled)
                    {
                        return;
                    }
                    throw coEx;
                }
            }
        }
예제 #12
0
파일: PropertyNode.cs 프로젝트: brobits/ATF
 private void SubscribeValueChanged()
 {
     foreach (object instance in Instances)
     {
         m_descriptor.AddValueChanged(instance, Instance_PropertyValueChanged);
     }
 }
예제 #13
0
 public DescriptorAdapter(object target, PropertyDescriptor descriptor)
 {
     _target               = target;
     _descriptor           = descriptor;
     _valueChangedCallback = newValue => { };
     _descriptor.AddValueChanged(target, OnValueChanged);
 }
예제 #14
0
        public Matrix()
        {
            InitializeComponent();

            PropertyDescriptor pdSL = DependencyPropertyDescriptor.FromProperty(Matrix.SwimLaneViewProperty, typeof(Matrix));

            pdSL.AddValueChanged(this, new System.EventHandler(SwimLanePropertyChanged));
        }
 // Token: 0x06008DF6 RID: 36342 RVA: 0x0025AC58 File Offset: 0x00258E58
 public ValueChangedRecord(ValueChangedEventManager manager, object source, PropertyDescriptor pd)
 {
     this._manager   = manager;
     this._source    = source;
     this._pd        = pd;
     this._eventArgs = new ValueChangedEventArgs(pd);
     pd.AddValueChanged(source, new EventHandler(this.OnValueChanged));
 }
예제 #16
0
 public void SubscribeToValueChange(object obj)
 {
     if (_prop.SupportsChangeEvents)
     {
         _prop.AddValueChanged(obj, ValueChanged);
         _prevOb.Target = obj;
     }
 }
예제 #17
0
        private static void OverridePropertyOnChanged(ToolBarTray toolBarTray, DependencyProperty property, EventHandler handler)
        {
            PropertyDescriptor propertyDescriptor = DependencyPropertyDescriptor.FromProperty(property, typeof(ToolBar));

            foreach (var toolBar in toolBarTray.ToolBars)
            {
                propertyDescriptor.AddValueChanged(toolBar, handler);
            }
        }
예제 #18
0
 /// <summary>
 /// This function asigns a source and property to this viewmodel.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="property">The Property.</param>
 public virtual void Initialize(object source, PropertyDescriptor property)
 {
     Source   = source;
     Property = property;
     Property.AddValueChanged(source, delegate
     {
         OnValueChanged();
     });
 }
        public override void AddValueChanged(object component, EventHandler handler)
        {
            if (_parentPD != null)
            {
                component = _parentPD.GetValue(component);
            }

            _currentPD.AddValueChanged(component, handler);
        }
예제 #20
0
        private static void OverrideColumnsPropertyOnChanged(DataGrid dataGrid, DependencyProperty property, EventHandler handler)
        {
            PropertyDescriptor propertyDescriptor = DependencyPropertyDescriptor.FromProperty(property, typeof(DataGridColumn));

            foreach (DataGridColumn column in dataGrid.Columns)
            {
                propertyDescriptor.AddValueChanged(column, handler);
            }
        }
예제 #21
0
 /// <summary>
 /// Subscribes to the ValueChanged event.
 /// </summary>
 protected void SubscribeValueChanged(PropertyDescriptor descriptor, EventHandler handler)
 {
     if (IsEnumerable)
     {
         var list = Instance as IEnumerable;
         if (list == null)
         {
             throw new InvalidOperationException("Instance should be a list.");
         }
         foreach (object item in list)
         {
             descriptor.AddValueChanged(GetPropertyOwner(descriptor, item), handler);
         }
     }
     else
     {
         descriptor.AddValueChanged(GetPropertyOwner(descriptor, Instance), handler);
     }
 }
예제 #22
0
        //- - - - - - - - - - - - - - - - - - - - - - - -
        #endregion

        #region auto center Events
        //- - - - - - - - - - - - - - - - - - - - - - - -
        void CarouselPanel_Loaded(object sender, RoutedEventArgs e)
        {
            SurfaceScrollViewer ssv = ScrollOwner as SurfaceScrollViewer;

            if (ssv != null)
            {
                PropertyDescriptor prop = TypeDescriptor.GetProperties(typeof(SurfaceScrollViewer))["IsScrolling"];
                prop.AddValueChanged(ssv, new EventHandler(this.ScrollEnded));
            }
        }
예제 #23
0
        protected override void Arrange()
        {
            base.Arrange();

            expirationPollFrequency = CacheManager.Property("ExpirationPollFrequencyInSeconds");
            componentModelExpirationPollFrequency = CacheManagerTypeDescriptor.GetProperties().OfType <PropertyDescriptor>().Where(x => x.Name == "ExpirationPollFrequencyInSeconds").First();

            expirationPollFrequencyChanged = false;

            componentModelExpirationPollFrequency.AddValueChanged(CacheManagerTypeDescriptor, new EventHandler((sender, args) => expirationPollFrequencyChanged = true));
        }
예제 #24
0
        /// <summary>
        /// Starts listenting to value changes by adding an event handler.
        /// </summary>
        private void AddValueChanged()
        {
            if (SourceObject == null || PropertyDescriptor == null)
            {
                return;
            }

            PropertyDescriptor.AddValueChanged(SourceObject, OnValueChanged);

            isListening = true;
        }
        protected override void Arrange()
        {
            base.Arrange();

            traceOutputOptions = TraceListener.Property("TraceOutputOptions");
            componentModelTraceOutputOptions = TraceListenerTypeDescriptor.GetProperties().OfType <PropertyDescriptor>().Where(x => x.Name == "TraceOutputOptions").First();

            expirationPollFrequencyChanged = false;

            componentModelTraceOutputOptions.AddValueChanged(TraceListenerTypeDescriptor, new EventHandler((sender, args) => expirationPollFrequencyChanged = true));
        }
예제 #26
0
        private void RegisterLoad()
        {
            if (!AssociatedObject.IsLoaded || string.IsNullOrWhiteSpace(_screenHostAutoKey))
            {
                return;
            }

            _timer.Tick += OnTimerTick;
            foreach (var column in AssociatedObject.Columns)
            {
                _propertyDescriptor.AddValueChanged(column, new EventHandler(OnColumnWidthPropertyChanged));
            }
        }
예제 #27
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="descriptor"></param>
        /// <param name="owner"></param>
        public Property(object instance, PropertyDescriptor descriptor, PropertyEditor owner)
            : base(owner)
        {
            Instance   = instance;
            Descriptor = descriptor;

            Name    = descriptor.Name;
            Header  = descriptor.DisplayName;
            ToolTip = descriptor.Description;

            // todo: is this ok? could it be a weak event?
            Descriptor.AddValueChanged(Instance, InstancePropertyChanged);
        }
        public void RaiseAddedValueChangedHandler()
        {
            var component  = new DescriptorTestComponent();
            var properties = TypeDescriptor.GetProperties(component.GetType());
            PropertyDescriptor propertyDescriptor = properties.Find(nameof(component.Property), false);
            var          handlerWasCalled         = false;
            EventHandler valueChangedHandler      = (_, __) => handlerWasCalled = true;

            propertyDescriptor.AddValueChanged(component, valueChangedHandler);
            propertyDescriptor.SetValue(component, int.MaxValue);

            Assert.True(handlerWasCalled);
        }
        public void GetTypeDescriptorGetPropertiesWrappedPropertyDescriptor_AddValueChanged_Success()
        {
            var provider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(ClassWithMetadataOnAnotherClass));
            PropertyDescriptorCollection properties = provider.GetTypeDescriptor(typeof(ClassWithMetadataOnAnotherClass), null).GetProperties();
            PropertyDescriptor           descriptor = properties[nameof(ClassWithMetadataOnAnotherClass.FirstName)];

            var          component = new ClassWithMetadataOnAnotherClass();
            int          callCount = 0;
            EventHandler handler   = (sender, e) => callCount++;

            descriptor.AddValueChanged(component, handler);
            descriptor.SetValue(component, "value");
            Assert.Equal(1, callCount);
        }
예제 #30
0
        public void RefreshDescriptors(PropertyDescriptor descriptor)
        {
            Name        = descriptor.Name;
            _descriptor = descriptor;

            IsBrowsable   = descriptor.IsBrowsable;
            _isReadOnly   = descriptor.IsReadOnly;
            _description  = descriptor.Description;
            CategoryName  = descriptor.Category;
            IsLocalizable = descriptor.IsLocalizable;

            Metadata = new AttributesContainer(descriptor.Attributes);
            _descriptor.AddValueChanged(Component, ComponentValueChanged);
        }