Example #1
0
        private void HandleDrag(object sender, Dock thumbposition, double delta)
        {
            BeatContainerAdorner adorner   = (BeatContainerAdorner)sender;
            UIElement            container = adorner.AdornedElement;

            TimeSpan changedSpan = ViewPort.Multiply(delta / ActualWidth);

            switch (thumbposition)
            {
            case Dock.Left:
            {
                TimeSpan duration = GetDuration(container) - changedSpan;
                TimeSpan position = GetPosition(container) + changedSpan;

                SetDuration(container, duration);
                SetPosition(container, position);
                break;
            }

            case Dock.Right:
            {
                TimeSpan duration = GetDuration(container) + changedSpan;
                SetDuration(container, duration);
                break;
            }

            case Dock.Top:
            {
                TimeSpan position = GetPosition(container) + changedSpan;
                SetPosition(container, position);
                break;
            }
            }
        }
Example #2
0
        private void EnsureAdorners()
        {
            List <BeatContainer> containers = new List <BeatContainer>();

            foreach (UIElement element in InternalChildren)
            {
                if (element is BeatContainer)
                {
                    containers.Add((BeatContainer)element);
                }
            }

            var removed = _adorners.Where(kvp => !containers.Contains(kvp.Key)).ToList();
            var added   = containers.Where(c => !_adorners.ContainsKey(c)).ToList();

            if (added.Count > 0 || removed.Count > 0)
            {
                AdornerLayer layer = AdornerLayer.GetAdornerLayer(this);

                foreach (KeyValuePair <UIElement, BeatContainerAdorner> container in removed)
                {
                    BeatContainerAdorner adorner = container.Value;
                    adorner.DragEnded   -= AdornerOnDragEnded;
                    adorner.DragStarted -= AdornerOnDragStarted;
                    adorner.DragDelta   -= AdornerOnDragDelta;

                    _adorners.Remove(container.Key);
                    layer.Remove(adorner);
                }

                foreach (BeatContainer container in added)
                {
                    BeatContainerAdorner adorner = new BeatContainerAdorner(container);
                    adorner.DragEnded   += AdornerOnDragEnded;
                    adorner.DragStarted += AdornerOnDragStarted;
                    adorner.DragDelta   += AdornerOnDragDelta;
                    _adorners.Add(container, adorner);
                    layer.Add(adorner);
                }
            }
        }