12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
-
- ///////////////////////////////////////////////////////////////////////////////
- //Copyright (c) 2016, 北京探索者软件公司
- //All rights reserved.
- //文件名称: GridCellSingleClickEditBehavior.cs
- //文件描述: 窗格单击编辑行为
- //创 建 者: xls
- //创建日期: 2017-1-11
- //版 本 号:1.0.0.0
- ////////////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Interactivity;
- namespace FWindSoft.Wpf.Behaviors
- {
- public class GridCellSingleClickEditBehavior : Behavior<UIElement>
- {
- protected override void OnAttached()
- {
- base.OnAttached();
- this.AssociatedObject.PreviewMouseLeftButtonDown += AssociatedObject_PreviewMouseLeftButtonDown;
- }
- protected override void OnDetaching()
- {
- base.OnDetaching();
- this.AssociatedObject.PreviewMouseRightButtonDown -= AssociatedObject_PreviewMouseLeftButtonDown;
- }
- private void AssociatedObject_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
- {
- UIElement uiel = e.OriginalSource as UIElement;
- if (uiel == null)
- return;
- var cell = uiel.GetParentType<DataGridCell>();
- if (cell == null)
- return;
- if (!cell.IsEditing && !cell.IsReadOnly)
- {
- if (!cell.IsFocused)
- cell.Focus();
- DataGrid grid = cell.GetParentType<DataGrid>();
- if (grid != null)
- {
- if (grid.SelectionUnit != DataGridSelectionUnit.FullRow)
- {
- if (!cell.IsSelected)
- {
- cell.IsSelected = true;
- }
- }
- else
- {
- DataGridRow row = cell.GetParentType<DataGridRow>();
- if (row != null && !row.IsSelected)
- {
- row.IsSelected = true;
- }
- }
- }
- }
- }
- }
- }
|