using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using FWindSoft.Wpf; using FWindSoft.Wpf.Controls; using FWindSoft.Wpf.History; using FWindSoft.Wpf.SystemTypeExtensions; namespace Test { /* 0、前置场景,单元格进入编辑状态,在单元格的右下下方出现可点击按钮,鼠标左键落下之后,移动之后进入拖动状态 1、进入拖动状态后,dataGrid的SelecteUnit设置成cell,增加mouseMove事件 2、拖动结束之后,复原拖动前的状态。这里所谓的拖动,只能模拟拖动的动作步骤。 3、根据拖动过程中,选中的单元格进行一一赋值 要求,在不改变控件的基础上,对功能进行扩充 */ /// /// WinDataGridTest.xaml 的交互逻辑 /// public partial class WinDataGridTest : Window { public WinDataGridTest() { InitializeComponent(); Collection = new ObservableCollection(); for (int i = 0; i < 20; i++) { Collection.Add(new BaseTest() {Checked= i==0, C = "c" + (i+1), Inner = new InnerTest() { InnerA = "A" + (i + 1), InnerB = "B" + (i + 1), IsListenEditing = true }, IsListenEditing = true }); } this.DataContext = this; this.Loaded += WinDataGridTest_Loaded; } private void WinDataGridTest_Loaded(object sender, RoutedEventArgs e) { } public ObservableCollection Collection { get; set; } private void Button_Click(object sender, RoutedEventArgs e) { var edit = Grid.SelectedItem as EditableItem; if (edit != null) { MessageBox.Show(edit.GetEditedState().ToString()); } } #region 拖拽展示模块 private Popup m_DragPopup; private TextBlock m_DragPopupValueContainer; private Popup CreatePopup(out TextBlock textBlock) { if (m_DragPopup != null) { textBlock = m_DragPopupValueContainer; return m_DragPopup; } Popup result = new Popup(); textBlock = new TextBlock() {Width=50, FontSize=14,FontWeight=FontWeights.Bold, VerticalAlignment =VerticalAlignment.Center}; textBlock.Margin = new Thickness(8, 0, 0, 0); result.IsHitTestVisible = false; result.Placement = PlacementMode.Mouse; result.AllowsTransparency = true; Border border = new Border() { BorderBrush =Brushes.LightSteelBlue,BorderThickness=new Thickness(2),Background=Brushes.White,Opacity=0.75}; border.Child = textBlock; result.Child = border; return result; } private void ShowPopup(MouseEventArgs e) { if (m_DragPopup == null) return; m_DragPopup.IsOpen = false; m_DragPopup.IsOpen = true; //var grid = (e.OriginalSource as FrameworkElement).GetSpecifyParrentType(); // Size popupSize = new Size(m_DragPopup.ActualWidth, m_DragPopup.ActualHeight); //if (!m_DragPopup.IsOpen) //{ // m_DragPopup.IsOpen = true; //} //Size popupSize = new Size(m_DragPopup.ActualWidth, m_DragPopup.ActualHeight); //Size popupSize = new Size(50, 30); //m_DragPopup.PlacementRectangle = new Rect(e.GetPosition(grid), popupSize); } public void SetPoputValue(object value) { object dispalyValue = value ?? string.Empty; m_DragPopupValueContainer.Text = dispalyValue.ToString(); } #endregion } public class CopyHandle : ICopy { public void CopyValue(object baseItem, object targetItem) { var useBase = baseItem as BaseTest; var targetBase = targetItem as BaseTest; if (useBase == null || targetBase == null) return; targetBase.Inner.InnerA = useBase.Inner.InnerA; } } }