Example #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();
            }
        }
Example #2
0
        /// <summary>
        /// Move selected item down
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnMoveDown_Click(object sender, RoutedEventArgs e)
        {
            var list = from RecordEntitySetting item in this.lvRight.SelectedItems
                       orderby SelectedList.IndexOf(item) descending
                       select new Tuple <RecordEntitySetting, int>(item, SelectedList.IndexOf(item));

            foreach (var l in list)
            {
                SelectedList.Remove(l.Item1);
                SelectedList.Insert(l.Item2 + 1, l.Item1);
            }

            UpdateReorderButtons();
            UpdateListViews();
        }
Example #3
0
        /// <summary>
        /// Add visual indicator of drag n drop location
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ListViewItem_DragOver(object sender, DragEventArgs e)
        {
            if (CanDragReorder)
            {
                var lvi = sender as ListViewItem;
                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);

                lvi.BorderBrush = new SolidColorBrush(Colors.Black);

                if (sourcePos > destPos)
                {
                    lvi.BorderThickness = new Thickness(0, 1, 0, 0);
                    lvi.Padding         = new Thickness(5, 1, 5, 2);
                }
                else if (sourcePos < destPos)
                {
                    lvi.BorderThickness = new Thickness(0, 0, 0, 1);
                    lvi.Padding         = new Thickness(5, 2, 5, 1);
                }
            }
        }