-
遍历WPF DataGrid单元格
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Media;
-
- namespace Splash.WPF
- {
- public static class DataGridPlus
- {
-
-
-
-
-
-
-
- public static DataGridCell GetCell(this DataGrid dataGrid, int rowIndex, int columnIndex)
- {
- DataGridRow rowContainer = dataGrid.GetRow(rowIndex);
- if (rowContainer != null)
- {
- DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
- DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);
- if (cell == null)
- {
- dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[columnIndex]);
- cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);
- }
- return cell;
- }
- return null;
- }
-
-
-
-
-
-
-
- public static DataGridRow GetRow(this DataGrid dataGrid, int rowIndex)
- {
- DataGridRow rowContainer = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);
- if (rowContainer == null)
- {
- dataGrid.UpdateLayout();
- dataGrid.ScrollIntoView(dataGrid.Items[rowIndex]);
- rowContainer = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);
- }
- return rowContainer;
- }
-
-
-
-
-
-
-
- public static T GetVisualChild<T>(Visual parent) where T : Visual
- {
- T child = default(T);
- int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
- for (int i = 0; i < numVisuals; i++)
- {
- Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
- child = v as T;
- if (child == null)
- {
- child = GetVisualChild<T>(v);
- }
- if (child != null)
- {
- break;
- }
- }
- return child;
- }
- }
- }
-
相关阅读:
糍粑大叔的独游之旅-战斗!之弹道实现
攻击判定流程研究: 瀑布算法、圆桌算法、混合算法解析
GitHub排名TOP30的机器学习开源项目/贪心学院
学习ES7+ES8
k8s Ipvs 内部网络自动分配和内部网络一致ip地址,导致ip冲突
Linux操作系统load average过高,kworker占用较多cpu
chrome断点调试&&其他技巧
Mongodb更新数组$pull修饰符 (mongodb 修改器($inc/$set/$unset/$push/$pop/upsert))
记一次线上Java程序导致服务器CPU占用率过高的问题排除过程
解决并发问题,数据库常用的两把锁(转)
-
原文地址:https://www.cnblogs.com/HelloXZ/p/3799582.html
Copyright © 2020-2023
润新知