获取Silverlight拖放中的drop index

获取Silverlight拖放中的drop index,第1张

概述此 article显示了如何在drop事件上实现复制 *** 作.我想做同样的事情,但我希望我删除的项目根据它放在UI上的位置出现在集合中.因此,当ObservableCollection发生更改时,我需要与NotifyCollectionChangedEventArgs类似的StartIndex.在本文中,您将看到最终获得的SelectionCollection对象,其项目具有Index属性.但不幸的是 此 article显示了如何在drop事件上实现复制 *** 作.我想做同样的事情,但我希望我删除的项目根据它放在UI上的位置出现在集合中.因此,当ObservableCollection发生更改时,我需要与NotifyCollectionChangedEventArgs类似的StartIndex.在本文中,您将看到最终获得的SelectionCollection对象,其项目具有Index属性.但不幸的是,这是源集合的索引(它被选中)而不是目标集合(它被删除的位置).解决方法 好吧,这很难看,但我没有找到另一种方式,不是我自己也不是通过搜索网络寻找答案.一定是微软的另一个截止日期,阻止了相当明显的功能被包括在内……

基本上,下面的方法手动执行所有 *** 作,获取放置位置并检查列表框项目以用作索引引用.

private voID @R_419_6818@BoxDragDropTarget_Drop(object sender,Microsoft.windows.DragEventArgs e){    // only valID for copying    if (e.Effects.HasFlag(DragDropEffects.copy))    {        SelectionCollection selections = ((ItemDragEventArgs)e.Data.GetData("System.windows.Controls.ItemDragEventArgs")).Data as SelectionCollection;        int? index = null;        if (selections != null)        {            Point p1 = e.Getposition(this.LayoutRoot); // get drop position relative to layout root            var elements = VisualTreeHelper.FindElementsInHostCoordinates(p1,this.LayoutRoot); // get ui elements at drop location            foreach (var dataItem in this.lbxConfiguration.Items) // iteration over data items            {                // get @R_419_6818@Box item from data item                @R_419_6818@BoxItem lbxItem = this.lbxConfiguration.ItemContainerGenerator.ContainerFromItem(dataItem) as @R_419_6818@BoxItem;                // find @R_419_6818@Box item that contains drop location                if (elements.Contains(lbxItem))                {                    Point p2 = e.Getposition(lbxItem); // get drop position relative to @R_419_6818@Box item                    index = this.lbxConfiguration.Items.IndexOf(dataItem); // new item will be inserted immediately before @R_419_6818@Box item                    if (p2.Y > lbxItem.ActualHeight / 2)                        index += 1; // new item will be inserted after @R_419_6818@Box item (drop location was in bottom half of @R_419_6818@Box item)                    break;                }            }            if (index != null)            {                foreach (var selection in selections)                {                    // adding a new item to the @R_419_6818@Box - adjust this to your model                    (lbxConfiguration.ItemsSource as I@R_419_6818@<VIEwItem>).Insert((int)index,(selection.Item as VIEwItem).Clone());                }            }        }    }}
总结

以上是内存溢出为你收集整理的获取Silverlight拖放中的drop index全部内容,希望文章能够帮你解决获取Silverlight拖放中的drop index所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1007400.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存