Exemplo n.º 1
0
        protected override void SetStringValue(string value)
        {
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(value);

            var globalKeyItems = Constants.LoadKeyItems(xmlDoc);

            this.KeyItems = new ObservableCollection <KeyItemViewModel>(globalKeyItems.Select(kvp => new KeyItemViewModel(kvp.Key, kvp.Value)));

            this.SelectedKeyItem = this.KeyItems.FirstOrDefault();
        }
Exemplo n.º 2
0
        private void KeyItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            for (var i = 0; i < this.KeyItems.Count; i++)
            {
                this.KeyItems[i].Index = i;
            }

            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (var newObject in e.NewItems)
                {
                    var newMessage = newObject as MessageViewModel;
                    if (newMessage != null)
                    {
                        newMessage.PropertyChanged += this.KeyItemIsDirtyChanged;
                    }
                }
            }

            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (var oldObject in e.OldItems)
                {
                    var oldMessage = oldObject as MessageViewModel;
                    if (oldMessage != null)
                    {
                        oldMessage.PropertyChanged -= this.KeyItemIsDirtyChanged;
                    }
                }
            }

            if (!this.KeyItems.Contains(this.SelectedKeyItem))
            {
                this.SelectedKeyItem = this.lastSelectedIndex < this.KeyItems.Count && this.lastSelectedIndex >= 0 ? this.KeyItems[this.lastSelectedIndex] : this.KeyItems.LastOrDefault();
            }

            this.OnPropertyChanged(nameof(this.KeyItems));
            this.OnPropertyChanged(nameof(this.IsDirty));
        }