public override bool ConvertChildClientPoint(ref System.Drawing.Point clientPointWinForms, out string childUIObject) { childUIObject = string.Empty; var clientPoint = new Point(clientPointWinForms.X, clientPointWinForms.Y); //指定座標の要素取得 var hitElement = PointUtility.GetPosElement(clientPoint, _control); if (hitElement == null) { return(false); } //DataGridCell取得 DataGridCell cell = null; foreach (var x in TreeUtilityInTarget.VisualTree(hitElement, TreeRunDirection.Ancestors)) { if (Equals(x, _control)) { break; } cell = x as DataGridCell; if (cell != null) { break; } } if (cell == null) { return(false); } var row = DataGridRow.GetRowContainingElement(cell); if (row == null) { return(false); } int rowindex = row.GetIndex(); var colIndex = cell.Column.DisplayIndex; //座標変換 var screenPos = _control.PointToScreen(clientPoint); var childPoint = cell.PointFromScreen(screenPos); clientPointWinForms.X = (int)childPoint.X; clientPointWinForms.Y = (int)childPoint.Y; childUIObject = $".GetCell({rowindex}, {colIndex})"; return(true); }
public override bool ConvertChildClientPoint(ref System.Drawing.Point clientPointWinForms, out string childUIObject) { childUIObject = string.Empty; var clientPoint = new Point(clientPointWinForms.X, clientPointWinForms.Y); //指定座標の要素取得 var hitElement = PointUtility.GetPosElement(clientPoint, _control); if (hitElement == null) { return(false); } //Item取得 ListBoxItem item = null; foreach (var x in TreeUtilityInTarget.VisualTree(hitElement, TreeRunDirection.Ancestors)) { if (Equals(x, _control)) { break; } item = x as ListBoxItem; if (item != null) { break; } } if (item == null) { return(false); } var index = _control.ItemContainerGenerator.IndexFromContainer(item); //座標変換 var screenPos = _control.PointToScreen(clientPoint); var childPoint = item.PointFromScreen(screenPos); clientPointWinForms.X = (int)childPoint.X; clientPointWinForms.Y = (int)childPoint.Y; childUIObject = $".GetItem({index})"; return(true); }
public override bool ConvertChildClientPoint(ref System.Drawing.Point clientPointWinForms, out string childUIObject) { childUIObject = string.Empty; var clientPoint = new Point(clientPointWinForms.X, clientPointWinForms.Y); //指定座標の要素取得 var hitElement = PointUtility.GetPosElement(clientPoint, _control); if (hitElement == null) { return(false); } //TreeItemをたどる var items = new List <TreeViewItem>(); foreach (var x in TreeUtilityInTarget.VisualTree(hitElement, TreeRunDirection.Ancestors)) { if (Equals(x, _control)) { break; } var item = x as TreeViewItem; if (item != null) { items.Add(item); } } if (items.Count == 0) { return(false); } //座標変換 var screenPos = _control.PointToScreen(clientPoint); var childPoint = items[0].PointFromScreen(screenPos); clientPointWinForms.X = (int)childPoint.X; clientPointWinForms.Y = (int)childPoint.Y; //子取得用文字列作成 items.Reverse(); var texts = new List <string>(); foreach (var x in items) { texts.Add(HeaderedItemsControlUtility.GetItemText(x)); } var indices = new List <int>(); ItemsControl itemsControl = _control; foreach (var x in items) { indices.Add(itemsControl.ItemContainerGenerator.IndexFromContainer(x)); itemsControl = x; } childUIObject = $".GetItem({MakeGetArgs(IsTextKey, indices.ToArray(), texts.ToArray())})"; return(true); }