Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        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;
            }
        }
Ejemplo n.º 5
0
        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");
        }
Ejemplo n.º 7
0
        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");
        }
Ejemplo n.º 8
0
        private void OnItemUpClicked(object sender, RoutedEventArgs e)
        {
            ListInspectorItem itemControl = (ListInspectorItem)sender;

            this.MoveItem(itemControl, -1);
        }
        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 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);
        }