static void OnKeyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { CorrelationDataWrapper wrapper = sender as CorrelationDataWrapper; if ((wrapper != null) && (!wrapper.isValidating)) { wrapper.isValidating = true; CorrelationDataWrapper.Editor.ValidateKey(wrapper, (string)e.OldValue); wrapper.isValidating = false; } }
//user clicked Add new data void OnAddNewDataExecuted(object sender, ExecutedRoutedEventArgs e) { //generate unique dictionary key string keyName = this.CorrelationInitializeData.GetUniqueName <CorrelationDataWrapper>(KeyPrefix, item => item.Key); //create new key value pair and add it to the dictionary CorrelationDataWrapper wrapper = new CorrelationDataWrapper(keyName, null); this.CorrelationInitializeData.Add(wrapper); //begin row edit after adding new entry this.correlationDataDGHelper.BeginRowEdit(wrapper, this.correlationInitializers.Columns[1]); }
internal void ValidateKey(CorrelationDataWrapper wrapper, string oldKey) { string newKey = wrapper.Key; if (string.IsNullOrEmpty(newKey)) { ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, System.Activities.Core.Presentation.SR.NullOrEmptyKeyName)); wrapper.Key = oldKey; } else { // At this point, the key of the entry has already been changed. If there are // entries with duplicate keys, the number of those entries is greater than 1. // Thus, we only need to check the entry count. int entryCount = this.CorrelationInitializeData.Count(entry => entry.Key == newKey); if (entryCount > 1) { ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, System.Activities.Core.Presentation.SR.DuplicateKeyName, newKey)); wrapper.Key = oldKey; } } }
//user clicked Add new data void OnAddNewDataExecuted(object sender, ExecutedRoutedEventArgs e) { //generate unique dictionary key string keyName = this.CorrelationInitializeData.GetUniqueName<CorrelationDataWrapper>(KeyPrefix, item => item.Key); //create new key value pair and add it to the dictionary CorrelationDataWrapper wrapper = new CorrelationDataWrapper(keyName, null); this.CorrelationInitializeData.Add(wrapper); //begin row edit after adding new entry this.correlationDataDGHelper.BeginRowEdit(wrapper, this.correlationInitializers.Columns[1]); }
internal void ValidateKey(CorrelationDataWrapper wrapper, string oldKey) { string newKey = wrapper.Key; if (string.IsNullOrEmpty(newKey)) { ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, System.Activities.Core.Presentation.SR.NullOrEmptyKeyName)); wrapper.Key = oldKey; } else { // At this point, the key of the entry has already been changed. If there are // entries with duplicate keys, the number of those entries is greater than 1. // Thus, we only need to check the entry count. int entryCount = this.CorrelationInitializeData.Count(entry => entry.Key == newKey); if (entryCount > 1) { ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, System.Activities.Core.Presentation.SR.DuplicateKeyName, newKey)); wrapper.Key = oldKey; } } }