WinDataGridTest.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Controls.Primitives;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using FWindSoft.Wpf;
  11. using FWindSoft.Wpf.Controls;
  12. using FWindSoft.Wpf.History;
  13. using FWindSoft.Wpf.SystemTypeExtensions;
  14. namespace Test
  15. {
  16. /*
  17. 0、前置场景,单元格进入编辑状态,在单元格的右下下方出现可点击按钮,鼠标左键落下之后,移动之后进入拖动状态
  18. 1、进入拖动状态后,dataGrid的SelecteUnit设置成cell,增加mouseMove事件
  19. 2、拖动结束之后,复原拖动前的状态。这里所谓的拖动,只能模拟拖动的动作步骤。
  20. 3、根据拖动过程中,选中的单元格进行一一赋值
  21. 要求,在不改变控件的基础上,对功能进行扩充
  22. */
  23. /// <summary>
  24. /// WinDataGridTest.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class WinDataGridTest : Window
  27. {
  28. public WinDataGridTest()
  29. {
  30. InitializeComponent();
  31. Collection = new ObservableCollection<BaseTest>();
  32. for (int i = 0; i < 20; i++)
  33. {
  34. 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 });
  35. }
  36. this.DataContext = this;
  37. this.Loaded += WinDataGridTest_Loaded;
  38. }
  39. private void WinDataGridTest_Loaded(object sender, RoutedEventArgs e)
  40. {
  41. }
  42. public ObservableCollection<BaseTest> Collection { get; set; }
  43. private void Button_Click(object sender, RoutedEventArgs e)
  44. {
  45. var edit = Grid.SelectedItem as EditableItem;
  46. if (edit != null)
  47. {
  48. MessageBox.Show(edit.GetEditedState().ToString());
  49. }
  50. }
  51. #region 拖拽展示模块
  52. private Popup m_DragPopup;
  53. private TextBlock m_DragPopupValueContainer;
  54. private Popup CreatePopup(out TextBlock textBlock)
  55. {
  56. if (m_DragPopup != null)
  57. {
  58. textBlock = m_DragPopupValueContainer;
  59. return m_DragPopup;
  60. }
  61. Popup result = new Popup();
  62. textBlock = new TextBlock() {Width=50, FontSize=14,FontWeight=FontWeights.Bold, VerticalAlignment =VerticalAlignment.Center};
  63. textBlock.Margin = new Thickness(8, 0, 0, 0);
  64. result.IsHitTestVisible = false;
  65. result.Placement = PlacementMode.Mouse;
  66. result.AllowsTransparency = true;
  67. Border border = new Border() { BorderBrush =Brushes.LightSteelBlue,BorderThickness=new Thickness(2),Background=Brushes.White,Opacity=0.75};
  68. border.Child = textBlock;
  69. result.Child = border;
  70. return result;
  71. }
  72. private void ShowPopup(MouseEventArgs e)
  73. {
  74. if (m_DragPopup == null)
  75. return;
  76. m_DragPopup.IsOpen = false;
  77. m_DragPopup.IsOpen = true;
  78. //var grid = (e.OriginalSource as FrameworkElement).GetSpecifyParrentType<DataGrid>();
  79. // Size popupSize = new Size(m_DragPopup.ActualWidth, m_DragPopup.ActualHeight);
  80. //if (!m_DragPopup.IsOpen)
  81. //{
  82. // m_DragPopup.IsOpen = true;
  83. //}
  84. //Size popupSize = new Size(m_DragPopup.ActualWidth, m_DragPopup.ActualHeight);
  85. //Size popupSize = new Size(50, 30);
  86. //m_DragPopup.PlacementRectangle = new Rect(e.GetPosition(grid), popupSize);
  87. }
  88. public void SetPoputValue(object value)
  89. {
  90. object dispalyValue = value ?? string.Empty;
  91. m_DragPopupValueContainer.Text = dispalyValue.ToString();
  92. }
  93. #endregion
  94. }
  95. public class CopyHandle : ICopy
  96. {
  97. public void CopyValue(object baseItem, object targetItem)
  98. {
  99. var useBase = baseItem as BaseTest;
  100. var targetBase = targetItem as BaseTest;
  101. if (useBase == null || targetBase == null)
  102. return;
  103. targetBase.Inner.InnerA = useBase.Inner.InnerA;
  104. }
  105. }
  106. }