Example #1
0
        public void ShouldReturnParentValue()
        {
            PropertyItemValue value    = new PropertyItemValue(new PropertyItemMock());
            PropertyItem      property = new PropertyItemMock(value);

            Assert.AreEqual(value, property.ParentValue);
        }
Example #2
0
        public override void ShowDialog(PropertyItemValue propertyValue, IInputElement commandSource)
        {
            if (propertyValue == null)
            {
                return;
            }
            if (propertyValue.ParentProperty.IsReadOnly)
            {
                return;
            }

            var ofd = new OpenFileDialog();

            ofd.Multiselect = false;

            var property = propertyValue.ParentProperty;

            if (property != null)
            {
                var optionsAttribute = (OpenFileDialogOptionsAttribute)property.Attributes[typeof(OpenFileDialogOptionsAttribute)];
                if (optionsAttribute != null)
                {
                    optionsAttribute.ConfigureDialog(ofd);
                }
            }

            if (ofd.ShowDialog() == true)
            {
                propertyValue.StringValue = ofd.FileName;
            }
        }
Example #3
0
 public override void ClearValue(PropertyItemValue propertyValue, IInputElement commandSource)
 {
     if (propertyValue == null || propertyValue.IsReadOnly)
     {
         return;
     }
     propertyValue.StringValue = string.Empty;
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValueExceptionEventArgs"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="value">The value.</param>
 /// <param name="source">The source.</param>
 /// <param name="exception">The exception.</param>
 public ValueExceptionEventArgs(string message, PropertyItemValue value, ValueExceptionSource source, Exception exception)
 {
     if (message == null) throw new ArgumentNullException("message");
       if (value == null) throw new ArgumentNullException("value");
       if (exception == null) throw new ArgumentNullException("exception");
       _message = message;
       _value = value;
       _source = source;
       _exception = exception;
 }
        public override void ShowDialog(PropertyItemValue propertyValue, IInputElement commandSource)
        {
            if (propertyValue == null)
            {
                return;
            }
            if (!propertyValue.IsCollection)
            {
                return;
            }

            MessageBox.Show("Collection!");
        }
        private void WrapEventHandlers(PropertyItemValue target)
        {
            if (target == null)
            {
                return;
            }
            if (_wrappedEvents)
            {
                return;
            }

            target.PropertyChanged += ValuePropertyChanged;
            _wrappedEvents          = true;
        }
        private void UnwrapEventHandlers(PropertyItemValue target)
        {
            if (target == null)
            {
                return;
            }
            if (!_wrappedEvents)
            {
                return;
            }

            target.PropertyChanged -= ValuePropertyChanged;
            _wrappedEvents          = false;
        }
Example #8
0
        public CollectionItemValue(PropertyItemValue propertyItemValue, int index)
        {
            _propertyItemValue = propertyItemValue;
            _index             = index;

            var expandable = PropertyGridUtils.GetAttributes <ExpandableObjectAttribute>(Value);

            if (expandable.Any())
            {
                var descriptors = MetadataRepository.GetProperties(Value).Select(prop => prop.Descriptor);

                if (descriptors.Any())
                {
                    object objectValue;
                    if (Value is ICloneable valueToClone)
                    {
                        objectValue = valueToClone.Clone();
                    }
                    else
                    {
                        objectValue = Value;
                    }


                    HasSubProperties = true;

                    var properties = new GridEntryCollection <PropertyItem>();
                    foreach (PropertyDescriptor d in descriptors)
                    {
                        var item = new PropertyItem(_propertyItemValue.ParentProperty.Owner, objectValue, d);
                        item.IsBrowsable   = ShouldDisplayProperty(d);
                        item.ValueChanged += ItemOnValueChanged;
                        properties.Add(item);
                    }

                    if (_propertyItemValue.ParentProperty.Owner.PropertyComparer != null)
                    {
                        properties.Sort(_propertyItemValue.ParentProperty.Owner.PropertyComparer);
                    }

                    SubProperties = properties;
                }

                MetadataRepository.Remove(Value);
            }
        }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValueExceptionEventArgs"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="value">The value.</param>
 /// <param name="source">The source.</param>
 /// <param name="exception">The exception.</param>
 public ValueExceptionEventArgs(string message, PropertyItemValue value, ValueExceptionSource source, Exception exception)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     if (exception == null)
     {
         throw new ArgumentNullException("exception");
     }
     _message   = message;
     _value     = value;
     _source    = source;
     _exception = exception;
 }
Example #10
0
        public override void ShowDialog(PropertyItemValue propertyValue, IInputElement commandSource)
        {
            if (propertyValue == null)
            {
                return;
            }
            if (propertyValue.ParentProperty.IsReadOnly)
            {
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.AllowMultiple = false;

            openFileDialog.Filters = new List <FileDialogFilter>
            {
                new FileDialogFilter()
                {
                    Name         = "Image Files (*.jpg, *.png, *.bmp)"
                    , Extensions = new List <string>()
                    {
                        "jpg", "png", "bmp"
                    }
                }
            };

            var mainWindow = ApplicationExtension.GetMainWindow();

            openFileDialog.ShowAsync(mainWindow).ContinueWith(x =>
            {
                if (x.IsFaulted == false)
                {
                    string result = x.Result.FirstOrDefault();

                    if (string.IsNullOrEmpty(result) == false)
                    {
                        propertyValue.StringValue = result;
                    }
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Example #11
0
        public override void ShowDialog(PropertyItemValue propertyValue, IInputElement commandSource)
        {
            PropertyGrid propGrid = commandSource as PropertyGrid;
            string       lastPath = propertyValue.StringValue;

            if (propGrid == null)
            {
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "All files (*.*)|*.*";
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            openFileDialog.ShowDialog();

            propertyValue.StringValue = openFileDialog.FileName != String.Empty ? openFileDialog.FileName : lastPath;             // change this string and compile, the ui does not see this change
            propGrid.DoReload();
            propGrid.RaiseEvent(new PropertyValueChangedEventArgs(PropertyGrid.PropertyValueChangedEvent, propertyValue.ParentProperty, ""));
        }
Example #12
0
        public override void ShowDialog(PropertyItemValue propertyValue, IInputElement commandSource)
        {
            if (propertyValue == null)
            {
                return;
            }
            if (propertyValue.ParentProperty.IsReadOnly)
            {
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.AllowMultiple = false;

            var property = propertyValue.ParentProperty;

            if (property != null)
            {
                var optionsAttribute = (OpenFileDialogOptionsAttribute)property.Attributes[typeof(OpenFileDialogOptionsAttribute)];
                if (optionsAttribute != null)
                {
                    optionsAttribute.ConfigureDialog(openFileDialog);
                }
            }

            var mainWindow = ApplicationExtension.GetMainWindow();

            openFileDialog.ShowAsync(mainWindow).ContinueWith(x =>
            {
                if (x.IsFaulted == false)
                {
                    string result = x.Result.FirstOrDefault();

                    if (string.IsNullOrEmpty(result) == false)
                    {
                        propertyValue.StringValue = result;
                    }
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Example #13
0
        public override void ShowDialog(PropertyItemValue propertyValue, IInputElement commandSource)
        {
            if (propertyValue == null)
            {
                return;
            }
            if (propertyValue.ParentProperty.IsReadOnly)
            {
                return;
            }

            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter      = "Image Files (*.jpg, *.png, *.bmp)|*.jpg;*.png;*.bmp",
                Multiselect = false
            };

            if (ofd.ShowDialog() == true)
            {
                propertyValue.StringValue = ofd.FileName;
            }
        }
Example #14
0
        private void OnShowDialogEditor(object sender, ExecutedRoutedEventArgs e)
        {
            PropertyItemValue parameter = e.Parameter as PropertyItemValue;

            parameter?.ParentProperty?.Editor?.ShowDialog(parameter, this);
        }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyItem"/> class.
 /// </summary>
 /// <param name="parentValue">The parent value.</param>
 protected PropertyItem(PropertyItemValue parentValue)
 {
     _parentValue = parentValue;
 }
Example #16
0
        private void UnwrapEventHandlers(PropertyItemValue target)
        {
            if (target == null) return;
            if (!wrappedEvents) return;

            target.PropertyChanged -= ValuePropertyChanged;
            wrappedEvents = false;
        }
Example #17
0
        private void WrapEventHandlers(PropertyItemValue target)
        {
            if (target == null) return;
            if (wrappedEvents) return;

            target.PropertyChanged += ValuePropertyChanged;
            wrappedEvents = true;
        }
Example #18
0
 public PropertyItemMock(PropertyItemValue value) : base(value)
 {
 }
Example #19
0
 /// <summary>
 /// Shows the dialog for editing property value.
 /// </summary>
 /// <param name="propertyValue">The property value.</param>
 /// <param name="commandSource">The command source.</param>
 public virtual void ShowDialog(PropertyItemValue propertyValue, IInputElement commandSource)
 {
 }
Example #20
0
 public CollectionItemValue(PropertyItemValue propertyItemValue, int index)
 {
     _propertyItemValue = propertyItemValue;
     _index             = index;
 }
Example #21
0
 /// <summary>
 /// Shows the dialog for editing property value.
 /// </summary>
 /// <param name="propertyValue">The property value.</param>
 /// <param name="commandSource">The command source.</param>
 public virtual void ShowDialog(PropertyItemValue propertyValue, IInputElement commandSource)
 {
 }
Example #22
0
		public CollectionItemValue(PropertyItemValue propertyItemValue, int index)
		{
			_propertyItemValue = propertyItemValue;
			_index = index;
		}