Ejemplo n.º 1
0
        internal Size MeasureHeaderTemplate(GridColumnBase column, Size rect, GridQueryBounds bounds, ContentPresenter ctrl)
#endif
        {
#if UWP
            var _popUp = GetPopUp();
            _popUp.Child = ctrl;
            if (bounds == GridQueryBounds.Height)
            {
                ctrl.Margin = new Thickness(5, 3, 5, 3);
            }
            else
            {
                ctrl.Margin = new Thickness(10, 3, 10, 3);
            }
#endif
            ctrl.Measure(new Size());
            ctrl.Content         = column.HeaderText;
            ctrl.ContentTemplate = column.HeaderTemplate;
            var controlSize = Size.Empty;
            if (bounds == GridQueryBounds.Height)
            {
                double iconsWidth = 0;
                if (this.GridBase.SortColumnDescriptions.Any(item => item.ColumnName == column.MappingName))
                {
                    iconsWidth += SortIconWidth;
                }
                iconsWidth += column.GetFilterIconWidth();
                ctrl.Measure(new Size(rect.Width - iconsWidth, Double.PositiveInfinity));
                controlSize          = ctrl.DesiredSize;
                ctrl.ContentTemplate = null;
#if UWP
                _popUp.Child = null;
#endif
                if (controlSize.Height == 0)
                {
                    return(new Size(controlSize.Width, this.GridBase.HeaderRowHeight));
                }

                //When we calculate the height of the HeaderTemplate we need to add the  margin and padding
                return(new Size(controlSize.Width, controlSize.Height + margin.Top + margin.Bottom));
            }
            else
            {
                ctrl.Measure(new Size(Double.PositiveInfinity, rect.Height));
                controlSize          = ctrl.DesiredSize;
                ctrl.ContentTemplate = null;
#if UWP
                _popUp.Child = null;
#endif
                if (controlSize.Width == 0)
                {
                    return(new Size(150, controlSize.Height));
                }
            }

            return(controlSize);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the TextBlock to measure the text when the column sizer is <see cref="Syncfusion.UI.Xaml.Grid.GridLengthUnitType.SizeToCells"/> or <see cref="Syncfusion.UI.Xaml.Grid.GridLengthUnitType.Auto"/>.
        /// </summary>
        /// <param name="column">
        /// The corresponding column to get the TextBlock.
        /// </param>
        /// <param name="record">
        /// The corresponding record to get the TextBlock.
        /// </param>
        /// <param name="queryBounds">
        /// Indicates whether the text is measured based on the height or width of the cell.
        /// </param>
        /// <returns>
        /// Returns the TextBlock for the specified column and record.
        /// </returns>
        internal TextBlock GetTextBlock(GridColumnBase column, object record, GridQueryBounds queryBounds)
        {
            if (TextBlock == null)
            {
                TextBlock = new TextBlock();
            }

            if (record == null)
            {
                TextBlock.FontFamily  = FontFamily;
                TextBlock.FontStretch = FontStretch;

                //auto-row height calculation for headers and stacked header.
                if (queryBounds == GridQueryBounds.Height)
                {
                    TextBlock.Margin = new Thickness(5, 3, 5, 3);
                }
                else
                {
#if WPF
                    TextBlock.Margin = new Thickness(10, 3, 2, 3);
#else
                    TextBlock.Margin = new Thickness(10, 3, 10, 3);
#endif
                }

#if WPF
                //WPF-23198 While calculating the TextBlock size, we have to set the FontSize of TextBlock as same as in view.
                //For Header we have FontSize as 14 so we need to calculate the TextBlock size for header by using 14.
                TextBlock.FontSize   = 14;
                TextBlock.FontWeight = FontWeights.Normal;
#else
                TextBlock.FontSize   = 16;
                TextBlock.FontWeight = FontWeights.SemiBold;
#endif

                if (column != null)
                {
                    TextBlock.HorizontalAlignment = column.HorizontalHeaderContentAlignment;
                }
                cachedColumn = null;
            }
            else
            {
                if (cachedColumn != column)
                {
                    cachedColumn          = column;
                    TextBlock.FontFamily  = column != null && column.hasFontFamily ? GetFontFamily(column) : FontFamily;
                    TextBlock.Margin      = GetMargin(column, queryBounds);
                    TextBlock.FontSize    = column != null && column.hasFontSize ? GetFontSize(column) : FontSize;
                    TextBlock.FontWeight  = column != null && column.hasFontWeight ? GetFontWeight(column) : FontWeight;
                    TextBlock.FontStretch = column != null && column.hasFontStretch ? GetFontStretch(column) : FontStretch;
                }
            }
            TextBlock.TextWrapping = queryBounds == GridQueryBounds.Height ? TextWrapping.Wrap : TextWrapping.NoWrap;
            return(TextBlock);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the padding value for corresponding grid column.
        /// </summary>
        /// <param name="column">GridColumn</param>
        /// <returns>Thickness</returns>
        internal Thickness GetMargin(GridColumnBase column, GridQueryBounds queryBounds)
        {
            Thickness _margin = Margin;

            if (column != null && column.hasMargin)
            {
                _margin = GetMargin(column);
            }
            if (queryBounds == GridQueryBounds.Height)
#if WPF
            { _margin.Left -= 0.5; }
#else
            { _margin.Left -= 6; }
#endif
            return(_margin);
        }
        protected override Size MeasureTemplate(Size rect, object record, GridColumn column, GridQueryBounds bounds)
        {
            var data     = record.GetType().GetProperty(column.MappingName).GetValue(record);
            var datatext = Convert.ToString(data);

            FormattedText formattedtext = GetFormattedText(column, record, datatext);

            formattedtext.Trimming = TextTrimming.None;

            formattedtext.MaxTextWidth  = this.DataGrid.GetVisualContainer().ColumnWidths.DefaultLineSize;
            formattedtext.MaxTextHeight = double.MaxValue;

            if (formattedtext.MaxTextWidth > (Margin.Left + Margin.Right))
            {
                formattedtext.MaxTextWidth -= (Margin.Left + Margin.Right);
            }
            return(new Size(formattedtext.Width, formattedtext.Height));
        }
Ejemplo n.º 5
0
        internal Size MeasureTextByTextBlock(Size rectangle, string displayText, GridColumnBase column, object record, GridQueryBounds queryBound, TextBlock textBlock)
        {
            textBlock.Text = displayText;
            var parentBorder = new Border {
                Child = textBlock
            };

            if (queryBound == GridQueryBounds.Height)
            {
                if (column == null)
                {
                    textBlock.MaxWidth = rectangle.Width;
                }
                else
                {
                    textBlock.MaxWidth = column.IsHidden || column.Width == 0.0 ? GetDefaultLineSize() : rectangle.Width;
                }

                textBlock.MaxHeight = double.PositiveInfinity;
            }
            else
            {
                textBlock.MaxHeight = rectangle.Height;
                textBlock.MaxWidth  = double.PositiveInfinity;
                //Calculating MaxWidth for ParentBorder was created an issue when the Text size is Greater than VisualContainer.TotalExtent value. Hence we removing this code.
                //var totalWidth = this.dataGrid.VisualContainer.ColumnWidths.TotalExtent;
                //parentBorder.MaxWidth = totalWidth;
            }
            //WPF-19471 To get correct text area size , Must pass textblock maximum width and maximum height for measure text area
            parentBorder.Measure(new Size(textBlock.MaxWidth, textBlock.MaxHeight));
            parentBorder.Child = null;
            return(parentBorder.DesiredSize);
        }
Ejemplo n.º 6
0
 //overridden to not expand cell when mulitple selections are made
 public override Size CalculatePreferredCellSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
 {
     //if (style.Text.IndexOf(ddUser.ListSeparator) > -1)
     //{
     //    return new Size(Grid.Model.ColWidths[colIndex], Grid.Model.RowHeights[rowIndex]);
     //}
     return(base.CalculatePreferredCellSize(g, rowIndex, colIndex, style, queryBounds));
 }
Ejemplo n.º 7
0
        //used to provide optimal height and width for cell (as in grid.ColWidths.ResizeToFit calls)
        protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
        {
            Size sz = base.OnQueryPrefferedClientSize(g, rowIndex, colIndex, style, queryBounds);

            //adjust to allow for button width
            sz.Width = sz.Width + ButtonBarSize.Width;

            return(sz);
        }
Ejemplo n.º 8
0
        /// <override/>
        protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds GridQueryBounds)
        {
            Size size = base.OnQueryPrefferedClientSize(g, rowIndex, colIndex, style, GridQueryBounds);

            return(new Size(size.Width + 20, size.Height));            // base method already consides ButtonBarSize, but let's add some more pixels here.
        }
Ejemplo n.º 9
0
        internal Size MeasureTemplate(Size rect, object record, GridColumnBase column, GridQueryBounds bounds, ContentPresenter ctrl)
#endif
        {
#if UWP
            var _popUp = GetPopUp();
            _popUp.Child  = ctrl;
            ctrl.FontSize = column != null && column.hasFontSize ? GetFontSize(column) : FontSize;
            ctrl.ClearValue(ContentPresenter.MarginProperty);
#endif
            ctrl.Measure(new Size());
            if (column.GetType() == typeof(GridUnBoundColumn))
            {
                var contentValue      = (GridBase as SfDataGrid).GetUnBoundCellValue(column as GridColumn, record);
                var dataContextHelper = GetDataContextHelper(column, record);
                dataContextHelper.Value = contentValue;
                ctrl.Content            = dataContextHelper;
            }
            else
            {
                if (column.SetCellBoundValue)
                {
                    var dataContextHelper = GetDataContextHelper(column, record);
                    dataContextHelper.SetValueBinding(column.ValueBinding, record);
                    ctrl.Content = dataContextHelper;
                }
                else
                {
                    ctrl.DataContext = record;
                    ctrl.Content     = record;
                }
            }

            if (column.hasCellTemplate)
            {
                ctrl.ContentTemplate = column.CellTemplate;
            }
            else if (column.hasCellTemplateSelector)
            {
                ctrl.ContentTemplateSelector = column.CellTemplateSelector;
            }
            else
            {
                if (column.IsTemplate && GridBase.hasCellTemplateSelector)
                {
                    ctrl.ContentTemplateSelector = GridBase.CellTemplateSelector;
                }
            }

            var controlsize = Size.Empty;
            if (bounds == GridQueryBounds.Height)
            {
                var tectangleWidth = column.IsHidden || column.Width == 0.0 ? GetDefaultLineSize() : rect.Width;
                ctrl.Measure(new Size(tectangleWidth, Double.PositiveInfinity));
                controlsize = ctrl.DesiredSize.Height == 0 ? new Size(ctrl.DesiredSize.Width, this.GridBase.RowHeight) : ctrl.DesiredSize;
            }
            else
            {
                ctrl.Measure(new Size(Double.PositiveInfinity, rect.Height));
                controlsize = ctrl.DesiredSize.Width == 0 ? new Size(150, ctrl.DesiredSize.Height) : ctrl.DesiredSize;
            }
            ctrl.Content                 = null;
            ctrl.ContentTemplate         = null;
            ctrl.ContentTemplateSelector = null;
#if UWP
            _popUp.Child = null;
#endif
            return(controlsize);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Measures the size of the template when the column sizer is <see cref="Syncfusion.UI.Xaml.Grid.GridLengthUnitType.SizeToCells"/> or <see cref="Syncfusion.UI.Xaml.Grid.GridLengthUnitType.Auto"/>.
        /// </summary>
        /// <param name="rect">
        /// The corresponding display rectangle to measure the template.
        /// </param>
        /// <param name="record">
        /// The corresponding record to measure the template.
        /// </param>
        /// <param name="column">
        /// The corresponding column to measure the template.
        /// </param>
        /// <param name="bounds">
        /// Indicates whether the template is measured based on the height or width of the cell.
        /// </param>
        /// <returns>
        /// Returns the size of template.
        /// </returns>
#if WPF
        internal Size MeasureTemplate(Size rect, object record, GridColumnBase column, GridQueryBounds bounds, ContentControl ctrl)
Ejemplo n.º 11
0
            /// <summary>
            /// Calculates the preferred size of the cell based on its contents without margins and any buttons.
            /// </summary>
            /// <param name="g">The <see cref="System.Drawing.Graphics"/> context of the canvas.</param>
            /// <param name="rowIndex">The row index.</param>
            /// <param name="colIndex">The column index.</param>
            /// <param name="style">The <see cref="GridStyleInfo"/> object that holds cell information.</param>
            /// <param name="queryBounds">grsphical bounds</param>
            /// <returns>The optimal size of the cell.</returns>
            /// <override/>
            protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
            {
                Size size = base.OnQueryPrefferedClientSize(g, rowIndex, colIndex, style, queryBounds);

                size.Width += 12; // for sort triangle
                return(size);
            }
Ejemplo n.º 12
0
 protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
 {
     return(new Size(base.OnQueryPrefferedClientSize(g, rowIndex, colIndex, style, queryBounds).Width, 40));
 }
        protected override Size GetCellSize(Size rect, GridColumn column, object data, GridQueryBounds bounds)
        {
            //return empty size for merged cell
            var rowIndex         = this.DataGrid.ResolveToRowIndex(data);
            var columnIndex      = DataGrid.Columns.IndexOf(column);
            var covererdCellInfo = this.DataGrid.CoveredCells.GetCoveredCellInfo(rowIndex, columnIndex);

            if (covererdCellInfo != null)
            {
                return(Size.Empty);
            }
            return(base.GetCellSize(rect, column, data, bounds));
        }
Ejemplo n.º 14
0
        /// <override/>
        protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
        {
            Size size   = base.OnQueryPrefferedClientSize(g, rowIndex, colIndex, style, queryBounds);
            int  indent = 36;

            if (this.grid != null)
            {
                Node n = helper.GetNode(rowIndex);
                indent = (n.Indent + 1) * this.renderer.offSet + this.renderer.midPt + this.renderer.leftSide + 2;
            }

            return(new Size(size.Width + indent, size.Height));
        }
Ejemplo n.º 15
0
 protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
 {
     if (trackBarControlSize.IsEmpty)
     {
         TrackBar drawSlider = new TrackBar();
         trackBarControlSize         = drawSlider.Size;
         trackBarControlSize.Width  += 24;
         trackBarControlSize.Height += 10;
     }
     return(trackBarControlSize);
 }
        protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
        {
            Size s = base.OnQueryPrefferedClientSize(g, rowIndex, colIndex, style, queryBounds);

            s.Width = s.Width + ButtonBarSize.Width;
            return(s);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Measures the size of the header template for the specified column.
        /// </summary>
        /// <param name="column">
        /// The corresponding column to measure the header template.
        /// </param>
        /// <param name="rect">
        /// The corresponding display rectangle to measure the template.
        /// </param>
        /// <param name="bounds">
        /// Indicates whether the template is measured based on the height or width of the cell.
        /// </param>
        /// <returns>
        /// Returns the size of the header template for the specified column.
        /// </returns>
#if WPF
        internal Size MeasureHeaderTemplate(GridColumnBase column, Size rect, GridQueryBounds bounds, ContentControl ctrl)
Ejemplo n.º 18
0
        //Override this method to calculate proper control size and return the same.
        protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
        {
            if (Grid[rowIndex, colIndex].Tag == null)
            {
                throw new Exception("No User Control is tagged");
            }
            else
            {
                //Get the type of the control from Style.Tag
                Control userControl = Grid[rowIndex, colIndex].Tag as Control;

                //Calculate the size of the control
                Size size = userControl.Size;
                size.Height += 2;
                //return the size
                return(size);
            }
        }
Ejemplo n.º 19
0
        internal Size MeasureTextByFormattedText(Size rectangle, GridColumnBase column, object record, GridQueryBounds queryBound, FormattedText formattedtext)
        {
            formattedtext.Trimming = TextTrimming.None;
            if (queryBound == GridQueryBounds.Height)
            {
                formattedtext.MaxTextHeight = double.MaxValue;

                //if column is null, then stackedcolumn text is measured.
                if (column == null)
                {
                    formattedtext.MaxTextWidth = rectangle.Width;
                    //Here six is added to the formattedtext height,
                    //because while calculating auto-height for headers with textblock ( AllowMeasureTextByFormattedText as False), we have measured the textblock by top and bottom margin as 3.
                    return(new Size(formattedtext.Width, formattedtext.Height + 6));
                }
                else
                {
                    formattedtext.MaxTextWidth = column.IsHidden || column.Width == 0.0 ? GetDefaultLineSize() : rectangle.Width;
                }

                if (column.hasMargin)
                {
                    if (formattedtext.MaxTextWidth > (GetMargin(column).Left + GetMargin(column).Right))
                    {
                        formattedtext.MaxTextWidth -= (GetMargin(column).Left + GetMargin(column).Right);
                    }
                }

                else
                {
                    if (formattedtext.MaxTextWidth > (Margin.Left + Margin.Right))
                    {
                        formattedtext.MaxTextWidth -= (Margin.Left + Margin.Right);
                    }
                }

                //Here six is added to the formattedtext height,
                //because while calculating auto-height for headers with textblock ( AllowMeasureTextByFormattedText as False), we have measured the textblock by top and bottom margin as 3.
                if (record == null)
                {
                    return(new Size(formattedtext.Width, formattedtext.Height + 6));
                }

                return(new Size(formattedtext.Width, formattedtext.Height));
            }
            else
            {
                //The MaxTextWidth value must be between '0' and '3579139.40666667'
                formattedtext.MaxTextWidth  = 3579139;
                formattedtext.MaxTextHeight = double.MaxValue;
                if (column.hasMargin)
                {
                    return(new Size(formattedtext.Width + (GetMargin(column).Left + GetMargin(column).Right), formattedtext.Height));
                }
                else
                {
                    return(new Size(formattedtext.Width + (Margin.Left + Margin.Right), formattedtext.Height));
                }
            }
        }
Ejemplo n.º 20
0
        protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
        {
            PictureBoxStyleProperties sp = new PictureBoxStyleProperties(style);
            Image img = sp.Image;

            if (img != null)
            {
                return(img.Size);
            }
            return(base.OnQueryPrefferedClientSize(g, rowIndex, colIndex, style, queryBounds));
        }
Ejemplo n.º 21
0
        protected override Size MeasureTemplate(Size rect, object record, GridColumn column, GridQueryBounds bounds)
        {
            if (column is GridTextColumn)
            {
                string[] properties = column.MappingName.Split('.');
                object   data       = record;
                foreach (string property in properties)
                {
                    data = data?.GetType().GetProperty(property).GetValue(data);
                }
                string datatext = Convert.ToString(data);

                return(MeasureText(datatext, column));
            }
            return(rect);
        }