Exemplo n.º 1
0
        /// <summary>
        /// Ends a <see cref="VideoTimelineSegment"/> drag operation and cleans up resources.
        /// </summary>
        private void EndSegmentDrag()
        {
            _segmentDragAdorner?.Detach();
            _segmentDragAdorner = null;

            _isDraggingSegment = false;
            _segmentDragOrigin = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the <see cref="UIElement.PreviewDragLeave"/> routed event for the <see cref="tracksListBox"/>.
        /// </summary>
        /// <remarks>If a <see cref="VideoTimelineSegment"/> is being dragged, the drag operation is canceled.</remarks>
        /// <inheritdoc cref="DragEventHandler"/>
        private void OnTracksListBoxPreviewDragLeave(object sender, DragEventArgs e)
        {
            if (_isDraggingSegment)
            {
                _segmentDragAdorner?.Detach();
                _segmentDragAdorner = null;

                e.Handled = true;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the <see cref="UIElement.PreviewDragEnter"/> routed event for the <see cref="tracksListBox"/>.
        /// </summary>
        /// <remarks>Begins a dragging operation for a <see cref="VideoTimelineSegment"/>.</remarks>
        /// <inheritdoc cref="DragEventHandler"/>
        private void OnTracksListBoxPreviewDragEnter(object sender, DragEventArgs e)
        {
            if (_segmentDragAdorner == null)
            {
                Size?adornerRectangleSize = null;
                if (e.Data.GetDataPresent(typeof(SegmentViewModelWeakReference)) && e.Data.GetDataPresent(typeof(Size)))
                {
                    adornerRectangleSize = (Size)e.Data.GetData(typeof(Size));
                    _isDraggingSegment   = true;
                }
                else if (e.Data.GetDataPresent(typeof(WeakReference <AddTrackSegmentCommandParameters>)))
                {
                    if (!(e.Data.GetData(typeof(WeakReference <AddTrackSegmentCommandParameters>)) is WeakReference <AddTrackSegmentCommandParameters> addTrackSegmentActionDataRef) ||
                        !addTrackSegmentActionDataRef.TryGetTarget(out AddTrackSegmentCommandParameters addTrackSegmentActionData))
                    {
                        throw new InvalidOperationException($"Invalid reference to a {nameof(AddTrackSegmentCommandParameters)} object.");
                    }

                    Debug.Assert(tracksListBox.HasItems);

                    ListBoxItem listBoxItem = tracksListBox.ItemContainerGenerator.ContainerFromIndex(0) as ListBoxItem;
                    Debug.Assert(listBoxItem != null);

                    VideoTimelineTrack trackElement = listBoxItem.FindVisualChild <VideoTimelineTrack>();
                    Debug.Assert(trackElement != null);

                    double trackPixelsPerFrame = trackElement.PixelsPerFrame;
                    adornerRectangleSize = new Size(trackPixelsPerFrame * addTrackSegmentActionData.FrameDuration, trackElement.ActualHeight);
                    _segmentDragOrigin   = trackElement.TranslatePoint(new Point((addTrackSegmentActionData.FrameDuration / 2) * trackPixelsPerFrame, 0d), tracksListBox);

                    _isDraggingSegment = true;
                }
                else
                {
                    _isDraggingSegment = false;
                }

                if (_isDraggingSegment && adornerRectangleSize.HasValue)
                {
                    _segmentDragAdorner = new TrackSegmentDragAdorner(adornedElement: tracksListBox,
                                                                      segmentElementSize: adornerRectangleSize.Value);
                    _segmentDragAdorner.Attach();
                }
            }
        }