コード例 #1
0
        public void MoveAfterIndex()
        {
            // arrange
            var layerCollection = new LayerCollection();
            var layer1          = new MemoryLayer()
            {
                Name = "Layer1"
            };
            var layer2 = new MemoryLayer()
            {
                Name = "Layer2"
            };
            var layer3 = new MemoryLayer()
            {
                Name = "Layer3"
            };

            layerCollection.Add(layer1);
            layerCollection.Add(layer2);
            layerCollection.Add(layer3);

            // act
            layerCollection.Move(3, layer1);

            // assert
            var list = layerCollection.ToList();

            Assert.AreEqual(3, list.Count());
            Assert.NotNull(list[0]);
            Assert.AreEqual("Layer2", list[0].Name);
            Assert.NotNull(list[1]);
            Assert.AreEqual("Layer3", list[1].Name);
            Assert.NotNull(list[2]);
            Assert.AreEqual("Layer1", list[2].Name);
        }
コード例 #2
0
        /// <inheritdoc/>
        protected override void Initialize()
        {
            base.Initialize();

            if (!IsInDesignMode)
            {
                layers = Map.Layers;
                layers.CollectionChanged         += Layers_CollectionChanged;
                layers.LayerSelectabilityChanged += layers_LayerSelectabilityChanged;
                layers.LayerVisibilityChanged    += layers_LayerVisibilityChanged;

                UpdateLayerList();

                Tools.Reordering.GridReordering.apply(LayersStack, 1, null);

                Tools.Reordering.GridReordering.AddRowMovedHandler(LayersStack, (s, e) => layers.Move(layerIndices[e.SourceRow], layerIndices[e.TargetRow]));
                Tools.Reordering.GridReordering.AddAllowMoveRowHandler(LayersStack, (s, e) =>
                {
                    // only allow to move within the same primary category
                    int targetRow = Math.Min(layers.Count - 1, Math.Max(e.TargetRow, 0));

                    var sourceLayer = layers[layerIndices[e.SourceRow]];
                    var targetLayer = layers[layerIndices[targetRow]];

                    e.IsAllowed = sourceLayer != null && targetLayer != null &&
                                  sourceLayer.CanvasCategories != null && sourceLayer.CanvasCategories.Length != 0 &&
                                  targetLayer.CanvasCategories != null && targetLayer.CanvasCategories.Length != 0 &&
                                  sourceLayer.CanvasCategories[0] == targetLayer.CanvasCategories[0];
                });
            }

            // Adds this gadget to the gadget collection of the map as a layers gadget.
            Map.Gadgets.Add(GadgetType.Layers, this);
        }