public void OnElementValueChanged(StandaloneInspectorControl control, object newValue, ref bool outChangeValid) { CDictionaryEntryViewModel vm = control.DataContext as CDictionaryEntryViewModel; if (vm != null) { SetInspectorElementValue(vm.Key, newValue); } }
private void RemoveElement_Click(object sender, RoutedEventArgs e) { CDictionaryEntryViewModel vm = (CDictionaryEntryViewModel)((MenuItem)sender).DataContext; RemoveInspectorElementValue(vm.Index, vm.Key); HeaderText = m_displayedList.Count + " Elements"; CollectionList.ItemsSource = null; CollectionList.ItemsSource = m_displayedList; }
public void OnElementKeyChanged(StandaloneInspectorControl control, object newValue, ref bool outChangeValid) { CDictionaryEntryViewModel vm = control.DataContext as CDictionaryEntryViewModel; if (vm != null) { object oldKey = vm.Key; if (m_displayedList.Any(viewModel => SafeEquals(viewModel.Key, newValue))) { //New key is already part of dictionary. Revert key change outChangeValid = false; } else { SetInspectorElementKey(oldKey, newValue, vm.Value); } } }
public override void PropertyInfoChanged(CObjectProperty info) { base.PropertyInfoChanged(info); KeyType = PropertyInfo.ValueType.GenericTypeArguments[0]; ValueType = PropertyInfo.ValueType.GenericTypeArguments[1]; if (info.Value != null) { dynamic dictionary = info.Value; IDictionary dictionaryInterface = info.Value as IDictionary; var keyCollection = dictionaryInterface.Keys; var valueCollection = dictionaryInterface.Values; object[] keys = new object[keyCollection.Count]; object[] values = new object[valueCollection.Count]; keyCollection.CopyTo(keys, 0); valueCollection.CopyTo(values, 0); if (EqualsContentwise(dictionaryInterface, keys, values)) { HeaderText = m_displayedList.Count + " Elements"; return; } int count = dictionary.Count; if (m_displayedList.Count < count) { int oldSize = m_displayedList.Count; for (int i = oldSize; i < count; i++) { m_displayedList.Add(new CDictionaryEntryViewModel(i, keys[i], values[i], m_keyType, m_valueType)); } } else if (m_displayedList.Count > count) { m_displayedList.RemoveRange(count, m_displayedList.Count - count); } for (int i = 0; i < count; i++) { CDictionaryEntryViewModel model = m_displayedList[i]; model.Index = i; model.Key = keys[i]; model.Value = values[i]; model.KeyType = m_keyType; model.ValueType = m_valueType; } HeaderText = count + " Elements"; CollectionList.ItemsSource = null; CollectionList.ItemsSource = m_displayedList; } else { //Collection is null. Show empty collection instead m_displayedList.Clear(); HeaderText = "0 Elements"; CollectionList.ItemsSource = null; CollectionList.ItemsSource = m_displayedList; } }