Esempio n. 1
0
        public Rectangle GetCellBounds(int row, CellView cell, bool includeMargin)
        {
            ExListViewItem item = ListView.ItemContainerGenerator.ContainerFromIndex(row) as ExListViewItem;

            if (item == null)
            {
                return(Rectangle.Zero);
            }

            // this works only if the wpf layout remains the same
            try {
                var stackpanel   = VisualTreeHelper.GetChild(item, 0);
                var border       = VisualTreeHelper.GetChild(stackpanel, 0);
                var grid         = VisualTreeHelper.GetChild(border, 0);
                var rowpresenter = VisualTreeHelper.GetChild(grid, 1) as FrameworkElement;

                if (VisualTreeHelper.GetChildrenCount(rowpresenter) != view.Columns.Count)
                {
                    return(Rectangle.Zero);
                }

                var colpresenter = VisualTreeHelper.GetChild(rowpresenter, cellViews [cell].ColumnIndex) as FrameworkElement;
                var colchild     = VisualTreeHelper.GetChild(colpresenter, 0) as FrameworkElement;

                if (cellViews [cell].Column.Views.Count > 1 && colchild is System.Windows.Controls.StackPanel)
                {
                    var childStack = colchild as System.Windows.Controls.StackPanel;
                    if (childStack == null || VisualTreeHelper.GetChildrenCount(childStack) < cellViews [cell].CellIndex)
                    {
                        return(Rectangle.Zero);
                    }
                    var cellpresenter = VisualTreeHelper.GetChild(childStack, cellViews [cell].CellIndex) as FrameworkElement;
                    var position      = cellpresenter.TransformToAncestor(ListView).Transform(new System.Windows.Point(-ListView.Padding.Left, 0));
                    var rect          = new Rect(position, cellpresenter.RenderSize);
                    return(rect.ToXwtRect());
                }
                else
                {
                    var position = colchild.TransformToAncestor(ListView).Transform(new System.Windows.Point(-ListView.Padding.Left, 0));
                    var rect     = new Rect(position, colchild.RenderSize);
                    return(rect.ToXwtRect());
                }
            } catch (ArgumentOutOfRangeException) {
                return(Rectangle.Zero);
            } catch (ArgumentNullException) {
                return(Rectangle.Zero);
            }
        }
Esempio n. 2
0
        public Rectangle GetRowBounds(int row, bool includeMargin)
        {
            ExListViewItem item = ListView.ItemContainerGenerator.ContainerFromIndex(row) as ExListViewItem;

            if (item == null)
            {
                return(Rectangle.Zero);
            }

            // this works only if the wpf layout remains the same
            try {
                var stackpanel = VisualTreeHelper.GetChild(item, 0);
                var border     = VisualTreeHelper.GetChild(stackpanel, 0) as FrameworkElement;

                var rect = Rectangle.Zero;
                if (includeMargin)
                {
                    var position = border.TransformToAncestor(ListView).Transform(new System.Windows.Point(0, 0));
                    rect    = new Rect(position, border.RenderSize).ToXwtRect();
                    rect.X -= ListView.Padding.Left + ListView.BorderThickness.Left;
                }
                else
                {
                    var grid         = VisualTreeHelper.GetChild(border, 0);
                    var rowpresenter = VisualTreeHelper.GetChild(grid, 1) as FrameworkElement;
                    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(rowpresenter); i++)
                    {
                        var colpresenter = VisualTreeHelper.GetChild(rowpresenter, i) as FrameworkElement;
                        var colchild     = VisualTreeHelper.GetChild(colpresenter, 0) as FrameworkElement;
                        var cellcount    = VisualTreeHelper.GetChildrenCount(colchild);
                        if (cellcount > 1)
                        {
                            for (int j = 0; j < cellcount; j++)
                            {
                                var cell      = VisualTreeHelper.GetChild(colchild, j) as FrameworkElement;
                                var position  = cell.TransformToAncestor(ListView).Transform(new System.Windows.Point(-ListView.Padding.Left, 0));
                                var cell_rect = new Rect(position, cell.RenderSize).ToXwtRect();
                                if (rect == Rectangle.Zero)
                                {
                                    rect = cell_rect;
                                }
                                else
                                {
                                    rect = rect.Union(cell_rect);
                                }
                            }
                        }
                        else
                        {
                            var position  = colchild.TransformToAncestor(ListView).Transform(new System.Windows.Point(-ListView.Padding.Left, 0));
                            var cell_rect = new Rect(position, colchild.RenderSize).ToXwtRect();
                            if (rect == Rectangle.Zero)
                            {
                                rect = cell_rect;
                            }
                            else
                            {
                                rect = rect.Union(cell_rect);
                            }
                        }
                    }
                }

                return(rect);
            } catch (ArgumentOutOfRangeException) {
                return(Rectangle.Zero);
            } catch (ArgumentNullException) {
                return(Rectangle.Zero);
            }
        }