コード例 #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);
        }
コード例 #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);
        }
コード例 #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();
        }
コード例 #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;
            }
        }
コード例 #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();
        }
コード例 #6
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");
        }
コード例 #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");
        }
コード例 #8
0
        private void OnItemUpClicked(object sender, RoutedEventArgs e)
        {
            ListInspectorItem itemControl = (ListInspectorItem)sender;

            this.MoveItem(itemControl, -1);
        }
コード例 #9
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);
        }
コード例 #10
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);
        }