private async void Group_DragEnter(object sender, DragEventArgs e)
        {
            FrameworkElement senderElement = sender as FrameworkElement;

            DebugHelper.Assert(senderElement != null);

            IDatabaseGroupViewModel groupVm = senderElement.DataContext as IDatabaseGroupViewModel;

            DebugHelper.Assert(groupVm != null);

            IKeePassGroup thisGroup = groupVm.Node as IKeePassGroup;

            DebugHelper.Assert(thisGroup != null);

            DragOperationDeferral deferral = e.GetDeferral();

            string text = await e.DataView.GetTextAsync();

            if (!String.IsNullOrWhiteSpace(text) && thisGroup.CanAdopt(text))
            {
                e.AcceptedOperation = DataPackageOperation.Move;
                e.Handled           = true;
            }

            deferral.Complete();
        }
Example #2
0
        /// <summary>
        /// Handler for DragEnter events on breadcrumbs. Updates the AcceptedOperation
        /// property of <paramref name="e"/> based on the drop target.
        /// </summary>
        /// <param name="sender">The element receiving the DragEnter event.</param>
        /// <param name="e">DragEventArgs for the drag.</param>
        private async void Breadcrumb_DragEnter(object sender, DragEventArgs e)
        {
            // Get the group we are currently over...
            FrameworkElement senderElement = sender as FrameworkElement;

            DebugHelper.Assert(senderElement != null);

            Breadcrumb thisBreadcrumb = senderElement.DataContext as Breadcrumb;

            DebugHelper.Assert(thisBreadcrumb != null);

            IKeePassGroup thisGroup = thisBreadcrumb.Group;

            DebugHelper.Assert(thisGroup != null);

            // Update the DataPackageOperation of the drag event based on whether
            // we are dragging a node over a group (generally, yes).
            DragOperationDeferral deferral = e.GetDeferral();

            string text = await e.DataView.GetTextAsync();

            if (!String.IsNullOrWhiteSpace(text) && thisGroup.CanAdopt(text))
            {
                e.AcceptedOperation = DataPackageOperation.Move;
                e.Handled           = true;
            }

            deferral.Complete();
        }
        private async void Group_Drop(object sender, DragEventArgs e)
        {
            FrameworkElement senderElement = sender as FrameworkElement;

            DebugHelper.Assert(senderElement != null);

            IDatabaseGroupViewModel groupVm = senderElement.DataContext as IDatabaseGroupViewModel;

            DebugHelper.Assert(groupVm != null);

            IKeePassGroup thisGroup = groupVm.Node as IKeePassGroup;

            DebugHelper.Assert(thisGroup != null);

            DragOperationDeferral deferral = e.GetDeferral();

            string encodedUuid = await e.DataView.GetTextAsync();

            if (thisGroup.TryAdopt(encodedUuid))
            {
                DebugHelper.Trace($"Successfully moved node {encodedUuid} to new parent {thisGroup.Uuid.EncodedValue}");
                e.AcceptedOperation = DataPackageOperation.Move;
            }
            else
            {
                DebugHelper.Trace($"WARNING: Unable to locate dropped node {encodedUuid}");
                e.AcceptedOperation = DataPackageOperation.None;
            }

            e.Handled = true;
            deferral.Complete();
        }
Example #4
0
        private async void UserControl_Drop(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(StandardDataFormats.Text) == false)
            {
                return;
            }

            // We need to take a Deferral as we won't be able to confirm the end of the operation synchronously.
            DragOperationDeferral def = e.GetDeferral();

            string unique_id = await e.DataView.GetTextAsync(StandardDataFormats.Text) as string;

            if (unique_id == null)
            {
                throw new Exception("TabbedFrame drop operation failed. Did not receive a unique ID.");
            }

            e.AcceptedOperation = DataPackageOperation.Move;

            def.Complete();

            Navigator.MoveTab(unique_id, this.ViewModel);

            // A drop should activate the TabbedFrame too.
            Navigator.ShellData.ActiveFrameIndex = ViewModel.Index;
        }
Example #5
0
        /// <summary>
        /// Handler for drop events on breadcrumbs. Moves the dropped node into the target group,
        /// if appropriate.
        /// </summary>
        /// <param name="sender">The element receiving the drop event.</param>
        /// <param name="e">DragEventArgs for the drop.</param>
        private async void Breadcrumb_Drop(object sender, DragEventArgs e)
        {
            // First get the group we are dropping onto...
            FrameworkElement senderElement = sender as FrameworkElement;

            DebugHelper.Assert(senderElement != null);

            Breadcrumb thisBreadcrumb = senderElement.DataContext as Breadcrumb;

            DebugHelper.Assert(thisBreadcrumb != null);

            IKeePassGroup thisGroup = thisBreadcrumb.Group;

            DebugHelper.Assert(thisGroup != null);

            DragOperationDeferral deferral = e.GetDeferral();

            // Get the UUID of the dropped node - if possible, move it into this group.
            string encodedUuid = await e.DataView.GetTextAsync();

            if (thisGroup.TryAdopt(encodedUuid))
            {
                DebugHelper.Trace($"Successfully moved node {encodedUuid} to new parent {thisGroup.Uuid.EncodedValue}");
                e.AcceptedOperation = DataPackageOperation.Move;
            }
            else
            {
                DebugHelper.Trace($"WARNING: Unable to locate dropped node {encodedUuid}");
                e.AcceptedOperation = DataPackageOperation.None;
            }

            e.Handled = true;
            deferral.Complete();
        }
        private async void ListViewOnDragEnter(object sender, DragEventArgs dragEventArgs)
        {
            var listView = sender as ListView;

            if (listView == null)
            {
                return;
            }

            _lastScrollMode = ScrollViewer.GetVerticalScrollMode(listView);
            ScrollViewer.SetVerticalScrollMode(listView, ScrollMode.Disabled);

            Tuple <ListViewItem, int> currentOverItemAndIndex = GetCurrentOverItemAndIndex(dragEventArgs, listView);
            ListViewItem currentOverListViewItem = currentOverItemAndIndex.Item1;

            if (currentOverListViewItem == null)
            {
                return;
            }

            DragOperationDeferral dragOperationDeferral = dragEventArgs.GetDeferral();

            BitmapImage bitmapImage = await(await currentOverListViewItem.RenderTargetBitmapBuffer()).ToBitmapImage();

            dragEventArgs.DragUIOverride?.SetContentFromBitmapImage(bitmapImage);

            foreach (GroupedItem groupedItem in _dragGroupedItems)
            {
                groupedItem.Group?.Remove(groupedItem);
                groupedItem.Group = null;
            }

            dragEventArgs.Handled = true;
            dragOperationDeferral.Complete();
        }
Example #7
0
        public async void dropimg(object sender, DragEventArgs e)
        {
            DragOperationDeferral defer = e.GetDeferral();

            try
            {
                DataPackageView data_view = e.DataView;
                string          str       = await clipboard(data_view);

                clipboard_substitution(str);
            }
            finally
            {
                defer.Complete();
            }
        }
Example #8
0
        private void LeftEpisodeList_Drop(object sender, DragEventArgs e)
        {
            DragOperationDeferral def = e.GetDeferral();

            if (e.Data.Properties.TryGetValue("episodes", out object items))
            {
                Point        pos   = e.GetPosition(LeftEpisodeList.ItemsPanelRoot);
                ListViewItem lvi   = (ListViewItem)LeftEpisodeList.ContainerFromIndex(0);
                int          index = 0;

                if (lvi != null)
                {
                    double itemHeight = lvi.ActualHeight + lvi.Margin.Top + lvi.Margin.Bottom;
                    index = Math.Min(LeftEpisodeList.Items.Count - 1, (int)(pos.Y / itemHeight));

                    ListViewItem targetItem     = (ListViewItem)LeftEpisodeList.ContainerFromIndex(index);
                    Point        positionInItem = e.GetPosition(targetItem);

                    if (positionInItem.Y > itemHeight / 2)
                    {
                        index++;
                    }

                    index = Math.Min(LeftEpisodeList.Items.Count, index);
                }

                IList <object> objects = (IList <object>)items;
                if (objects.Count > 0)
                {
                    PlexViewModel.SelectedShow.MarkDirty();
                }

                foreach (object o in objects)
                {
                    Episode episode = (Episode)o;
                    PlexViewModel.RightSeason.RemoveEpisode(episode);
                    PlexViewModel.LeftSeason.InsertEpisode(index++, episode);
                }

                e.AcceptedOperation = DataPackageOperation.Move;
            }

            def.Complete();
        }
Example #9
0
        private async void dragGrid4_DragStarting(UIElement sender, DragStartingEventArgs args)
        {
            args.Data.SetText(sourceTextBlock4.Text);

            // 获取异步操作对象
            DragOperationDeferral deferral = args.GetDeferral();

            // 将 dragGrid4 截图,并以此创建一个 SoftwareBitmap 对象
            RenderTargetBitmap rtb = new RenderTargetBitmap();
            await rtb.RenderAsync(dragGrid4);

            IBuffer buffer = await rtb.GetPixelsAsync();

            SoftwareBitmap bitmap = SoftwareBitmap.CreateCopyFromBuffer(buffer, BitmapPixelFormat.Bgra8, rtb.PixelWidth, rtb.PixelHeight, BitmapAlphaMode.Premultiplied);

            // drag 过程中的 ui 为指定的 SoftwareBitmap
            args.DragUI.SetContentFromSoftwareBitmap(bitmap);

            // 完成异步操作
            deferral.Complete();
        }
Example #10
0
        private async void dropGrid4_DragEnter(object sender, DragEventArgs e)
        {
            e.AcceptedOperation      = DataPackageOperation.Copy;
            e.DragUIOverride.Caption = "我是文本";

            // 获取异步操作对象
            DragOperationDeferral deferral = e.GetDeferral();
            RenderTargetBitmap    rtb      = new RenderTargetBitmap();
            await rtb.RenderAsync(dragGrid);

            IBuffer buffer = await rtb.GetPixelsAsync();

            SoftwareBitmap bitmap = SoftwareBitmap.CreateCopyFromBuffer(buffer, BitmapPixelFormat.Bgra8, rtb.PixelWidth, rtb.PixelHeight, BitmapAlphaMode.Premultiplied);

            // drag 到 drop 区域后,drag 过程中的 ui 改为指定的 SoftwareBitmap
            e.DragUIOverride.SetContentFromSoftwareBitmap(bitmap);

            // 完成异步操作
            deferral.Complete();

            targetTextBlock4.Text += e.Modifiers;
            targetTextBlock4.Text += Environment.NewLine;
        }
Example #11
0
        private void ListBox_OnDrop(object sender, DragEventArgs e)
        {
            // If the item being dropped is a layer...
            if (e.DataView != null && e.DataView.Properties != null && e.DataView.Properties.Any(x => x.Key == "item" && x.Value is Layer))
            {
                try
                {
                    // Start doing work for the drop.
                    DragOperationDeferral deferral = e.GetDeferral();

                    // Get the layer that is being moved.
                    KeyValuePair <string, object> draggedItem = e.Data.Properties.FirstOrDefault(x => x.Key == "item");
                    Layer draggedLayer = draggedItem.Value as Layer;

                    // Find the source and destination views.
                    ListView destinationList = sender as ListView;
                    ListView sourceList      = _originListView;

                    // Remove the layer and re-add it.
                    ((LayerCollection)sourceList.ItemsSource).Remove(draggedLayer);
                    ((LayerCollection)destinationList.ItemsSource).Add(draggedLayer);

                    // Finish the drop.
                    deferral.Complete();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }
            }
            else
            {
                // Don't allow other things to be dropped (e.g. files from the desktop).
                e.AcceptedOperation = DataPackageOperation.None;
            }
        }
Example #12
0
        private async void ListView_Drop(object sender, DragEventArgs e)
        {
            ListView target = (ListView)sender;

            if (e.DataView.Contains(StandardDataFormats.Text))
            {
                DragOperationDeferral def = e.GetDeferral();
                string s = await e.DataView.GetTextAsync();

                var site = Newtonsoft.Json.JsonConvert.DeserializeObject <SiteMetaWithKey>(s);

                // Find the insertion index:
                Windows.Foundation.Point pos = e.GetPosition(target.ItemsPanelRoot);

                // Find which ListView is the target, find height of first item
                ListViewItem sampleItem;
                if (target.Name == "EnabledSitesListView")
                {
                    sampleItem = (ListViewItem)NotEnabledSitesListView.ContainerFromIndex(0);
                }
                else
                {
                    sampleItem = (ListViewItem)EnabledSitesListView.ContainerFromIndex(0);
                }

                // Adjust ItemHeight for margins
                double itemHeight = sampleItem.ActualHeight + sampleItem.Margin.Top + sampleItem.Margin.Bottom;

                // Find index based on dividing number of items by height of each item
                int index = Math.Min(target.Items.Count - 1, (int)(pos.Y / itemHeight));

                // Find the item that we want to drop
                ListViewItem targetItem = (ListViewItem)target.ContainerFromIndex(index);

                // Figure out if to insert above or below
                Windows.Foundation.Point positionInItem = e.GetPosition(targetItem);
                if (positionInItem.Y > itemHeight / 2)
                {
                    index++;
                }

                // Don't go out of bounds
                index = Math.Min(target.Items.Count, index);

                // Find correct source list
                if (target.Name == "EnabledSitesListView")
                {
                    EnabledSites.Insert(index, site);
                    foreach (var item in NotEnabledSites)
                    {
                        if (item.Key == site.Key)
                        {
                            NotEnabledSites.Remove(item);
                            break;
                        }
                    }
                }
                else if (target.Name == "NotEnabledSitesListView")
                {
                    NotEnabledSites.Insert(index, site);
                    foreach (var item in EnabledSites)
                    {
                        if (item.Key == site.Key)
                        {
                            EnabledSites.Remove(item);
                            break;
                        }
                    }
                }

                e.AcceptedOperation = DataPackageOperation.Move;
                def.Complete();
            }
        }
Example #13
0
        private async void ListView_Drop(object sender, DragEventArgs e)
        {
            ListView target = (ListView)sender;

            if (e.DataView.Contains(StandardDataFormats.Text))
            {
                DragOperationDeferral def = e.GetDeferral();
                string s = await e.DataView.GetTextAsync();

                string[] items = s.Split('\n');
                foreach (string item in items)
                {
                    // Create Contact object from string, add to existing target ListView
                    string[] info = item.Split(" ", 3);
                    Contact  temp = new Contact(info[0], info[1], info[2]);

                    // Find the insertion index:
                    Windows.Foundation.Point pos = e.GetPosition(target.ItemsPanelRoot);

                    // If the target ListView has items in it, use the heigh of the first item
                    //      to find the insertion index.
                    int index = 0;
                    if (target.Items.Count != 0)
                    {
                        // Get a reference to the first item in the ListView
                        ListViewItem sampleItem = (ListViewItem)target.ContainerFromIndex(0);

                        // Adjust itemHeight for margins
                        double itemHeight = sampleItem.ActualHeight + sampleItem.Margin.Top + sampleItem.Margin.Bottom;

                        // Find index based on dividing number of items by height of each item
                        index = Math.Min(target.Items.Count - 1, (int)(pos.Y / itemHeight));

                        // Find the item being dropped on top of.
                        ListViewItem targetItem = (ListViewItem)target.ContainerFromIndex(index);

                        // If the drop position is more than half-way down the item being dropped on
                        //      top of, increment the insertion index so the dropped item is inserted
                        //      below instead of above the item being dropped on top of.
                        Windows.Foundation.Point positionInItem = e.GetPosition(targetItem);
                        if (positionInItem.Y > itemHeight / 2)
                        {
                            index++;
                        }

                        // Don't go out of bounds
                        index = Math.Min(target.Items.Count, index);
                    }
                    // Only other case is if the target ListView has no items (the dropped item will be
                    //      the first). In that case, the insertion index will remain zero.

                    // Find correct source list
                    if (target.Name == "DragDropListView")
                    {
                        // Find the ItemsSource for the target ListView and insert
                        contacts1.Insert(index, temp);
                        //Go through source list and remove the items that are being moved
                        foreach (Contact contact in DragDropListView2.Items)
                        {
                            if (contact.FirstName == temp.FirstName && contact.LastName == temp.LastName && contact.Company == temp.Company)
                            {
                                contacts2.Remove(contact);
                                break;
                            }
                        }
                    }
                    else if (target.Name == "DragDropListView2")
                    {
                        contacts2.Insert(index, temp);
                        foreach (Contact contact in DragDropListView.Items)
                        {
                            if (contact.FirstName == temp.FirstName && contact.LastName == temp.LastName && contact.Company == temp.Company)
                            {
                                contacts1.Remove(contact);
                                break;
                            }
                        }
                    }
                }

                e.AcceptedOperation = DataPackageOperation.Move;
                def.Complete();
            }
        }
        private async void ListView_Drop(object sender, DragEventArgs e)
        {
            ListView target = (ListView)sender;

            if (e.DataView.Contains(StandardDataFormats.Text))
            {
                DragOperationDeferral def = e.GetDeferral();
                string s = await e.DataView.GetTextAsync();

                string[] items = s.Split('\n');
                foreach (string item in items)
                {
                    // Create Contact object from string, add to existing target ListView
                    string[] info = item.Split(" ", 3);
                    Contact  temp = new Contact(info[0], info[1], info[2]);

                    // Find the insertion index:
                    Windows.Foundation.Point pos = e.GetPosition(target.ItemsPanelRoot);

                    // Find which ListView is the target, find height of first item
                    ListViewItem sampleItem;
                    if (target.Name == "DragDropListView")
                    {
                        sampleItem = (ListViewItem)DragDropListView2.ContainerFromIndex(0);
                    }
                    // Only other case is target = DragDropListView2
                    else
                    {
                        sampleItem = (ListViewItem)DragDropListView.ContainerFromIndex(0);
                    }

                    // Adjust ItemHeight for margins
                    double itemHeight = sampleItem.ActualHeight + sampleItem.Margin.Top + sampleItem.Margin.Bottom;

                    // Find index based on dividing number of items by height of each item
                    int index = Math.Min(target.Items.Count - 1, (int)(pos.Y / itemHeight));

                    // Find the item that we want to drop
                    ListViewItem targetItem = (ListViewItem)target.ContainerFromIndex(index);;

                    // Figure out if to insert above or below
                    Windows.Foundation.Point positionInItem = e.GetPosition(targetItem);
                    if (positionInItem.Y > itemHeight / 2)
                    {
                        index++;
                    }

                    // Don't go out of bounds
                    index = Math.Min(target.Items.Count, index);

                    // Find correct source list
                    if (target.Name == "DragDropListView")
                    {
                        // Find the ItemsSource for the target ListView and insert
                        contacts1.Insert(index, temp);
                        //Go through source list and remove the items that are being moved
                        foreach (Contact contact in DragDropListView2.Items)
                        {
                            if (contact.FirstName == temp.FirstName && contact.LastName == temp.LastName && contact.Company == temp.Company)
                            {
                                contacts2.Remove(contact);
                                break;
                            }
                        }
                    }
                    else if (target.Name == "DragDropListView2")
                    {
                        contacts2.Insert(index, temp);
                        foreach (Contact contact in DragDropListView.Items)
                        {
                            if (contact.FirstName == temp.FirstName && contact.LastName == temp.LastName && contact.Company == temp.Company)
                            {
                                contacts1.Remove(contact);
                                break;
                            }
                        }
                    }
                }

                e.AcceptedOperation = DataPackageOperation.Move;
                def.Complete();
            }
        }
Example #15
0
        private void CanvasControl_Drop(object sender, DragEventArgs e)
        {
            DragOperationDeferral def = e.GetDeferral();

            def.Complete();

            if (App.Model.Drop.Clip != null)
            {
                Point p = e.GetPosition(CanvasControl);

                //Main:主剪辑
                if (p.Y < App.Setting.Space + App.Setting.RulerSpace)
                {
                    MediaClip clip          = App.Model.Drop.Clip.Clone();
                    TimeSpan  postion       = App.Model.ScreenToCanvas((float)p.X); //当前时间
                    TimeSpan  postiondouble = postion + postion;                    //双倍当前时间(为了与以后的start+end做比较计算)

                    if (App.Model.MediaComposition.Clips.Count == 0)                //轨道是空的
                    {
                        App.Model.MediaComposition.Clips.Add(clip);
                    }
                    else if (App.Model.MediaComposition.Clips.Count == 1)//轨道上只有一个
                    {
                        var First = App.Model.MediaComposition.Clips.First();

                        if (postiondouble < First.StartTimeInComposition + First.EndTimeInComposition)
                        {
                            App.Model.MediaComposition.Clips.Insert(0, clip);
                        }
                        else
                        {
                            App.Model.MediaComposition.Clips.Insert(1, clip);
                        }
                    }
                    else//轨道上有多个
                    {
                        //判断是否超出第一个剪辑的结束时间
                        MediaClip First = App.Model.MediaComposition.Clips.FirstOrDefault();
                        if (postiondouble < First.StartTimeInComposition + First.EndTimeInComposition)
                        {
                            App.Model.MediaComposition.Clips.Insert(0, clip);
                        }

                        //循环,寻找中间落脚点在哪里
                        TimeSpan OldStartAndEnd = TimeSpan.Zero;
                        for (int i = 1; i < App.Model.MediaComposition.Clips.Count; i++)
                        {
                            MediaClip Current = App.Model.MediaComposition.Clips[i];
                            //是否处于前一个媒体剪辑与后一个媒体剪辑的中点之间
                            if (postiondouble > OldStartAndEnd && postiondouble < Current.StartTimeInComposition + Current.EndTimeInComposition)
                            {
                                App.Model.MediaComposition.Clips.Insert(i, clip);
                            }

                            OldStartAndEnd = Current.StartTimeInComposition + Current.EndTimeInComposition;//新旧交替
                        }

                        //判断是否超出最后一个剪辑的结束时间
                        MediaClip Last = App.Model.MediaComposition.Clips.LastOrDefault();
                        if (postiondouble > Last.StartTimeInComposition + Last.EndTimeInComposition)
                        {
                            App.Model.MediaComposition.Clips.Insert(App.Model.MediaComposition.Clips.Count, clip);
                        }
                    }


                    //设此媒体剪辑为当前媒体剪辑当前
                    App.Model.Current        = clip;
                    App.Model.OverlayCurrent = null;
                }
                else
                {
                    //OverlayMove:覆盖移动
                    for (int i = 0; i < App.Model.MediaComposition.OverlayLayers.Count; i++)
                    {
                        float top    = App.Setting.RulerSpace + App.Setting.Space + i * App.Setting.OverlaySpace; //顶部
                        float height = App.Setting.OverlaySpace;                                                  //高度
                        float bottom = top + height;                                                              //底部

                        if (p.Y > top && p.Y < bottom)
                        {
                            App.Model.OverlayIndex = i;

                            MediaClip    clip    = App.Model.Drop.Clip.Clone();
                            MediaOverlay Overlay = new MediaOverlay(clip);
                            Overlay.Position = new Rect(100, 0, 666, 222);

                            App.Model.MediaComposition.OverlayLayers[i].Overlays.Add(Overlay);
                            Overlay.Delay = App.Model.ScreenToCanvas((float)p.X);

                            App.Model.Current        = null;
                            App.Model.OverlayCurrent = Overlay;
                            App.Model.AudioCurrent   = null;
                        }
                    }
                }

                App.Model.MediaPlayer.Source = MediaSource.CreateFromMediaStreamSource
                                               (
                    App.Model.MediaComposition.GeneratePreviewMediaStreamSource(0, 0)
                                               );

                this.MediaPlayerElement.SetMediaPlayer(App.Model.MediaPlayer);
                App.Model.Refresh++;//画布刷新


                App.Model.Drop = null;
            }
        }
Example #16
0
 public static IDisposable ToDisposable(this DragOperationDeferral d) => new Disposable(d.Complete);