Exemple #1
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (!_cells.Any())
            {
                return(finalSize);
            }

            var grid   = DataGridLite.GetGrid(this);
            var widths = grid.SpeculateColumnWidths(finalSize.Width);

            var left = 0d;

            for (var i = 0; i < widths.Length; i++)
            {
                var cell  = _cells[i];
                var width = widths[i];
                cell.Arrange(new Rect(left, 0, width, grid.RowHeight));
                left += width;
            }
            return(finalSize);
        }
Exemple #2
0
        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);

            if (e.Property == WidthProperty)
            {
                var rows = _cells.Select(LiteRow.GetRow).ToList();
                rows.ForEach(r => r.InvalidateArrange());
            }
            if (e.Property == HeaderTemplateProperty)
            {
                var grid = DataGridLite.GetGrid(this);
                if (grid == null)
                {
                    return;
                }
                grid.InvalidateHeader();
            }
            if (e.Property == CellTemplateProperty)
            {
                var grid = DataGridLite.GetGrid(this);
                if (grid == null)
                {
                    return;
                }
                grid.InvalidateRows();
            }
            if (e.Property == DataMemberProperty)
            {
                var dataPath = string.IsNullOrWhiteSpace(DataMember) ? "(0).Item" : "(0).Item." + DataMember;
                foreach (var element in _cells.OfType <FrameworkElement>())
                {
                    element.SetBinding(FrameworkElement.DataContextProperty, new Binding {
                        Path = new PropertyPath(dataPath, LiteRow.RowProperty.DependencyProperty), Source = element, Mode = BindingMode.OneWay
                    });
                }
            }
        }
Exemple #3
0
 private static void SetGrid(DependencyObject child, DataGridLite grid)
 {
     child.SetValue(GridProperty, grid);
 }