private void MoveItem(ListInspectorItem itemControl, int deltaMove) { if (deltaMove == 0) { return; } // Get control index. int itemIndex = this.Items.Children.IndexOf(itemControl); int newItemIndex = itemIndex + deltaMove; // Check range. if (newItemIndex < 0 || newItemIndex >= this.Items.Children.Count) { return; } var items = this.GetListToModify(); var item = items[itemIndex]; // Remove from old index. this.Items.Children.RemoveAt(itemIndex); items.RemoveAt(itemIndex); // Add to new index. this.Items.Children.Insert(newItemIndex, itemControl); items.Insert(newItemIndex, item); }
private void DeleteItemControl(ListInspectorItem itemControl) { // Unregister from events. itemControl.DeleteClicked -= this.OnItemDeleteClicked; itemControl.DownClicked -= this.OnItemDownClicked; itemControl.UpClicked -= this.OnItemUpClicked; itemControl.ValueChanged -= this.OnItemValueChanged; // Remove. this.Items.Children.Remove(itemControl); }
private void OnItemDeleteClicked(object sender, RoutedEventArgs e) { ListInspectorItem itemControl = (ListInspectorItem)sender; // Get control index. int itemIndex = this.Items.Children.IndexOf(itemControl); // Delete control. this.DeleteItemControl(itemControl); IList items = this.GetListToModify(); // Delete item from list. items.RemoveAt(itemIndex); // List changed. this.OnValueChanged(); }
private static void OnControlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { // Register for ValueChanged event. ListInspectorItem listInspectorItem = (ListInspectorItem)d; InspectorControl inspectorControl = (InspectorControl)e.OldValue; if (inspectorControl != null) { inspectorControl.ValueChanged -= listInspectorItem.OnValueChanged; } inspectorControl = (InspectorControl)e.NewValue; if (inspectorControl != null) { inspectorControl.ValueChanged += listInspectorItem.OnValueChanged; } }
private void OnItemValueChanged(object sender, RoutedEventArgs routedEventArgs) { ListInspectorItem.ValueChangedEventArgs eventArgs = (ListInspectorItem.ValueChangedEventArgs)routedEventArgs; ListInspectorItem itemControl = (ListInspectorItem)sender; // Get control index. int itemIndex = this.Items.Children.IndexOf(itemControl); IList items = this.GetListToModify(); items[itemIndex] = eventArgs.NewValue; // Mark as handled to not bubble up any more. eventArgs.Handled = true; // List changed. this.OnValueChanged(); }
private void AddItemControl(object item) { Console.WriteLine("Creating item control"); IInspectorControl propertyControl = this.inspectorFactory.CreateInspectorControlFor(this.itemInspectorProperty, item, false); Console.WriteLine("Creating new list inspector item"); // Create item wrapper. ListInspectorItem itemWrapperControl = new ListInspectorItem { Control = (InspectorControl)propertyControl }; itemWrapperControl.DeleteClicked += this.OnItemDeleteClicked; itemWrapperControl.DownClicked += this.OnItemDownClicked; itemWrapperControl.UpClicked += this.OnItemUpClicked; itemWrapperControl.ValueChanged += this.OnItemValueChanged; Console.WriteLine("Adding new list inspector item"); this.Items.Children.Add(itemWrapperControl); Console.WriteLine("Added new list inspector item"); }
private void OnItemUpClicked(object sender, RoutedEventArgs e) { ListInspectorItem itemControl = (ListInspectorItem)sender; this.MoveItem(itemControl, -1); }