Ejemplo n.º 1
0
        /// <summary>
        /// Assigns the property value to the property of every source element.
        /// </summary>
        /// <param name="value">Property value to be assigned.</param>
        public override void SetPropertyValue(object value)
        {
            // empty string values are treated as null...
            Html html = value as Html;

            if (html != null)
            {
                if (html.HtmlData.Trim() == string.Empty)
                {
                    html = null;
                }
            }

            using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Update property value - " + this.PropertyName))
            {
                PropertyGridEditorViewModel.SetPropertyValues(this.Elements, this.PropertyName, value);
                transaction.Commit();
            }

            // handle errors
            if (html != null)
            {
                if (html.ValidationResult.Count() > 0)
                {
                    // clear current error list
                    this.EventManager.GetEvent <ErrorListClearItems>().Publish(this);

                    // add serialization result items
                    List <BaseErrorListItemViewModel> items = new List <BaseErrorListItemViewModel>();
                    foreach (IValidationMessage validationmessage in html.ValidationResult)
                    {
                        StringErrorListItemViewModel item = new StringErrorListItemViewModel(this.ViewModelStore, validationmessage.MessageId, ModelErrorListItemViewModel.ConvertCategory(validationmessage.Type), validationmessage.Description);
                        items.Add(item);
                    }

                    // notify of change
                    this.EventManager.GetEvent <ErrorListAddItems>().Publish(items);
                }
            }
        }