Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6655133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:28:41+00:00 2026-05-26T01:28:41+00:00

I have a data grid where I need everything to have a fully scalable

  • 0

I have a data grid where I need everything to have a fully scalable size. I have no issue with the column headers, they all scale properly. My issue is for the individual cells, they do not seem to respect their binding.

The binding for grid height seems to set the initial value fine, but once the grid is displayed it does not change the height if the variable it is bound to changes.

I had to subclass DataGridTextColumn to add some custom functionality. I have a method called CreateDataGridColumn that returns a reference to ExtendedDataGridTextColumn. These columns are then added to the data grid. The data binding itself works fine, the grid shows all of the correct data.

Here is some code:

    private ExtendedDataGridTextColumn CreateDataGridColumn(EntityBase dataColumn, FormatConditionGroup formatConditionGroup)
    {
        ExtendedDataGridTextColumn newColumn = new ExtendedDataGridTextColumn(dataColumn);
        DataTemplate dataTemplate = new DataTemplate();
        String textBlockName = "Text" + dataColumn.EntityId;
        String columnTag = dataColumn.GetPropertyValue("Tag");

        // Create the TextBlock that will display the cell contents
        FrameworkElementFactory textBlockFNFactory;
        textBlockFNFactory = new FrameworkElementFactory(typeof(TextBlock));

        _gridTextHeightPercentage = dataColumn.GetPropertyDouble("GridFontSize", Constants.DefaultFontHeightPercent) / 2.8;
        _fontSize = GlobalVariables.DesignerPreviewHeight * (_gridTextHeightPercentage / 100);

        Binding binding = new Binding();
        binding.Source = _fontSize;
        textBlockFNFactory.SetBinding(TextBlock.FontSizeProperty, binding);

        // Do a whole bunch of stuff here

        // Create a border so that the label background does not obscure the grid lines
        FrameworkElementFactory borderFNFactory;
        borderFNFactory = new FrameworkElementFactory(typeof(Border));
        borderFNFactory.AppendChild(textBlockFNFactory);

        // Add type to data template
        dataTemplate.VisualTree = borderFNFactory;

        newColumn.CellTemplate = dataTemplate;

        return newColumn;
    }

Then I have the following method fired on the SizeChanged event for the datagrid:

        _customDataGrid.TitleAreaHeight = new GridLength(GlobalVariables.DesignerPreviewHeight * (_titleHeightPercentage / 100));
        _customDataGrid.SetHeaderFontSize(GlobalVariables.DesignerPreviewHeight * (_headerHeightPercentage / 100));
        _fontSize = GlobalVariables.DesignerPreviewHeight * (_gridTextHeightPercentage / 100); 

The first two lines do what they are supposed to, change the height of the title area which is something I added to my data grids and change the header height. The update of the _fontSize variable though does not change the data grid cell text height.

Updated

As per suggestion I added a dependency property as such.

    public static readonly DependencyProperty GridFontHeightProperty = DependencyProperty.Register("GridFontHeight", typeof(double), typeof(CustomDataGrid));

Then changed my binding code to this.

        binding = new Binding();
        binding.Path = new PropertyPath("GridFontHeight");
        textBlockFNFactory.SetBinding(TextBlock.FontSizeProperty, binding);

Then in my size changed added this.

        SetValue(GridFontHeightProperty, _fontSize);

But it does not work. In this scenario it doesn’t set the font height correctly to begin with, it just uses the default font height for the data grid.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:28:42+00:00Added an answer on May 26, 2026 at 1:28 am

    First of all, no you can’t bind to a private variable. My guess is, that your variable _fontSize is a private double, right? (See how i have to guess? ;))
    You can bind to a public property or to a dependency property, which in your case fits well. So create a new dependency Property called FontSize and bind to that.

    If for some reason you can’t use a dependency property, you can still bind to normal CLR properties using INotifyPropertyChanged which should look something like

    public double FontSize
    {
        get{return _fontSize;}
        set
        {
            _fontSize = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("FontSize"));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data grid in which I need to freeze the rightmost column.
Consider I have a data grid, I need to find the number of rows
I have a jQuery grid with data with user data. I need to handle
Lets say I have 2 columns in my data Grid: Column A: Selected, and
I have large data files of values on a 2D grid. They are organized
I have a Data Grid View inside a control that is displayed in a
I have a data grid that has a checkbox item renderer in a cloumn
BackGround: I have an advanced data grid. The data provider for this ADG is
Is it possible to have something like Data Grid or Grid View control in
I have a neat little javascript data grid and I want people to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.