| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 | using System;using System.Linq;using System.Windows.Media.Imaging;using InABox.Core;using InABox.DynamicGrid.Properties;using InABox.WPF;namespace InABox.DynamicGrid{    public enum DynamicRowMovement    {        Up,        Down    }    public class DynamicRowMovementColumn : DynamicImageColumn    {        private readonly BitmapImage downarrow = Resources.downarrow.AsBitmapImage();        private readonly Func<int, int, bool> Swap;        private readonly BitmapImage uparrow = Resources.uparrow.AsBitmapImage();        public DynamicRowMovementColumn(DynamicRowMovement direction, Func<int, int, bool> swap) : base(r => null)        {            Direction = direction;            Swap = swap;            Image = GetImage;            Action = MoveRow;            Position = DynamicActionColumnPosition.Start;        }        public DynamicRowMovement Direction { get; }        private bool IsFirst(CoreRow row)        {            return row != null && row.Table.Rows.First() == row; // (row.Index == 0);        }        private bool IsLast(CoreRow row)        {            return row != null && row.Table.Rows.Last() == row; //(row.Index == row.Table.Rows.Count - 1);        }        private BitmapImage GetImage(CoreRow row)        {            if (Direction.Equals(DynamicRowMovement.Up))                return IsFirst(row) ? null : uparrow;            return IsLast(row) ? null : downarrow;        }        private bool MoveRow(CoreRow row)        {            var tgt = row.Index + (Direction.Equals(DynamicRowMovement.Up) ? -1 : 1);            if (tgt > -1 && tgt < row.Table.Rows.Count)                return Swap(row.Index, tgt);            return false;        }    }}
 |