Esempio n. 1
0
        /// <summary>
        /// Handles dropping listviewitem for reordering
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lvRight_Drop(object sender, DragEventArgs e)
        {
            if (CanDragReorder)
            {
                RecordEntitySetting droppedData = e.Data.GetData(typeof(RecordEntitySetting)) as RecordEntitySetting;
                RecordEntitySetting target      = ((ListBoxItem)sender).DataContext as RecordEntitySetting;

                int sourcePos = SelectedList.IndexOf(droppedData);
                int destPos   = SelectedList.IndexOf(target);

                if (sourcePos < destPos)
                {
                    SelectedList.Insert(destPos + 1, droppedData);
                    SelectedList.RemoveAt(sourcePos);
                }
                else
                {
                    sourcePos++;

                    if (SelectedList.Count + 1 > sourcePos)
                    {
                        SelectedList.Insert(destPos, droppedData);
                        SelectedList.RemoveAt(sourcePos);
                    }
                }

                lvRight.ItemsSource = SelectedList.ToList();
                UpdateReorderButtons();
            }
        }