예제 #1
0
 /// <summary>
 /// Performs actions related to a property edit. Calls PropertyEdited event.</summary>
 /// <param name="e">Event args</param>
 protected virtual void OnPropertyEdited(PropertyEditedEventArgs e)
 {
     if (PropertyEdited != null)
     {
         PropertyEdited(this, e);
     }
 }
예제 #2
0
 private void m_propertyGrid_PropertyEdited(object sender, PropertyEditedEventArgs e)
 {
     var context = EditingContext.As<IHistoryContext>();
     if (context != null)
     {
         context.Dirty = true;
     }
 }
예제 #3
0
        /// <summary>
        /// Sets the property value to the new value</summary>
        /// <param name="owner">Object whose property is set</param>
        /// <param name="descriptor">Property descriptor</param>
        /// <param name="value">New property value</param>
        public static void SetProperty(object owner, PropertyDescriptor descriptor, object value)
        {
            try
            {
                TypeConverter converter = descriptor.Converter;
                if (converter != null &&
                    value != null &&
                    converter.CanConvertFrom(value.GetType()))
                {
                    value = converter.ConvertFrom(value);
                }

                bool   notifyChange = false;
                object oldValue     = null;
                EventHandler <PropertyEditedEventArgs> handler = PropertyEdited;
                if (handler != null)
                {
                    oldValue     = descriptor.GetValue(owner);
                    notifyChange = !PropertyUtils.AreEqual(oldValue, value);
                }
                descriptor.SetValue(owner, value);
                if (notifyChange)
                {
                    PropertyEditedEventArgs eventArgs = new PropertyEditedEventArgs(owner, descriptor, oldValue, value);
                    handler(null, eventArgs);
                }
            }
            catch (InvalidTransactionException)
            {
                // The transaction needs to be cancelled.
                throw;
            }
            catch (Exception ex)
            {
                PropertyErrorEventArgs eventArgs = new PropertyErrorEventArgs(owner, descriptor, ex);

                PropertyError.Raise(null, eventArgs);

                if (!eventArgs.Cancel)
                {
                    Outputs.WriteLine(OutputMessageType.Error, ex.Message);
                }
            }
        }
예제 #4
0
파일: GridView.cs 프로젝트: sbambach/ATF
 private void propertyEditingControl_PropertyEdited(object sender, PropertyEditedEventArgs e)
 {
     // figure out the index of the row that changed
     // keep an eye on this, if it gets slow we may need to replace with
     // a hash lookup
     int index = 0;
     foreach (object item in EditingContext.Items)
     {
         if (item.Equals(e.Owner))
         {
             // create a new event using the row index
             OnRowValueChanged(new RowChangedEventArgs(index));
             break;
         }
         index++;
     }
 }
예제 #5
0
 /// <summary>
 /// Raises the PropertyEdited event and performs custom processing</summary>
 /// <param name="e">PropertyErrorEventArgs containing event data</param>
 protected virtual void OnPropertyEdited(PropertyEditedEventArgs e)
 {
     PropertyEdited.Raise<PropertyEditedEventArgs>(this, e);
 }
예제 #6
0
 /// <summary>
 /// Performs actions related to a property edit. Calls PropertyEdited event.</summary>
 /// <param name="e">Event args</param>
 protected virtual void OnPropertyEdited(PropertyEditedEventArgs e)
 {
     if (PropertyEdited != null)
     {
         PropertyEdited(this, e);
     }
 }
예제 #7
0
        /// <summary>
        /// Sets the property value to the new value</summary>
        /// <param name="owner">Object whose property is set</param>
        /// <param name="descriptor">Property descriptor</param>
        /// <param name="value">New property value</param>
        public static void SetProperty(object owner, PropertyDescriptor descriptor, object value)
        {
            try
            {
                TypeConverter converter = descriptor.Converter;
                if (converter != null &&
                    value != null &&
                    converter.CanConvertFrom(value.GetType()))
                {
                    value = converter.ConvertFrom(value);
                }

                bool notifyChange = false;
                object oldValue = null;
                EventHandler<PropertyEditedEventArgs> handler = PropertyEdited;
                if (handler != null)
                {
                    oldValue = descriptor.GetValue(owner);
                    notifyChange = !PropertyUtils.AreEqual(oldValue, value);

                }
                descriptor.SetValue(owner, value);
                if (notifyChange)
                {
                    PropertyEditedEventArgs eventArgs = new PropertyEditedEventArgs(owner, descriptor, oldValue, value);
                    handler(null, eventArgs);
                }

            }
            catch (InvalidTransactionException)
            {
                // The transaction needs to be cancelled.
                throw;
            }
            catch (Exception ex)
            {
                PropertyErrorEventArgs eventArgs = new PropertyErrorEventArgs(owner, descriptor, ex);

                PropertyError.Raise(null, eventArgs);

                if (!eventArgs.Cancel)
                    Outputs.WriteLine(OutputMessageType.Error, ex.Message);
            }
        }